{"action":"created","comment":{"url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/comments/94285000","pull_request_review_id":14814268,"id":94285000,"diff_hunk":"@@ -0,0 +1,113 @@\n+﻿#region License\n+// Copyright (c) 2007 James Newton-King\n+//\n+// Permission is hereby granted, free of charge, to any person\n+// obtaining a copy of this software and associated documentation\n+// files (the \"Software\"), to deal in the Software without\n+// restriction, including without limitation the rights to use,\n+// copy, modify, merge, publish, distribute, sublicense, and/or sell\n+// copies of the Software, and to permit persons to whom the\n+// Software is furnished to do so, subject to the following\n+// conditions:\n+//\n+// The above copyright notice and this permission notice shall be\n+// included in all copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n+// OTHER DEALINGS IN THE SOFTWARE.\n+#endregion\n+\n+#if !(NET20 || NET35 || NET40 || PORTABLE40)\n+\n+using System;\n+using System.Diagnostics;\n+using System.IO;\n+using System.Threading;\n+using System.Threading.Tasks;\n+\n+namespace Newtonsoft.Json.Utilities\n+{\n+    internal static class AsyncUtils\n+    {\n+        private static readonly Action Nop = () =>\n+        {\n+        };\n+\n+        // Pre-allocate to avoid wasted allocations.\n+        public static readonly Task<bool> False = Task.FromResult(false);\n+        public static readonly Task<bool> True = Task.FromResult(true);\n+\n+        internal static Task<bool> ToAsync(this bool value) => value ? True : False;\n+\n+        public static Task CancelIfRequesedAsync(this CancellationToken cancellationToken)\n+        {\n+            return cancellationToken.IsCancellationRequested ? CancelledAsync(cancellationToken) : null;\n+        }\n+\n+        public static Task<T> CancelIfRequesedAsync<T>(this CancellationToken cancellationToken)\n+        {\n+            return cancellationToken.IsCancellationRequested ? CancelledAsync<T>(cancellationToken) : null;\n+        }\n+\n+        public static Task CancelledAsync(this CancellationToken cancellationToken)\n+        {\n+            Debug.Assert(cancellationToken.IsCancellationRequested);\n+            return new Task(Nop, cancellationToken);\n+        }\n+\n+        public static Task<T> CancelledAsync<T>(this CancellationToken cancellationToken)\n+        {\n+            Debug.Assert(cancellationToken.IsCancellationRequested);\n+            return new Task<T>(() => default(T), cancellationToken);\n+        }\n+\n+        // Task.Delay(0) is optimised as a cached task within the framework, and indeed\n+        // the same cached task that Task.CompletedTask returns as of 4.6, but we'll add\n+        // our own property for previous frameworks.\n+        internal static Task CompletedTask => Task.Delay(0);","path":"Src/Newtonsoft.Json/Utilities/AsyncUtils.cs","position":73,"original_position":73,"commit_id":"3809b8d4317c5a629b5e3f6aec9c8b5ee70e74c1","original_commit_id":"3809b8d4317c5a629b5e3f6aec9c8b5ee70e74c1","user":{"login":"benaadams","id":1142958,"avatar_url":"https://avatars.githubusercontent.com/u/1142958?v=3","gravatar_id":"","url":"https://api.github.com/users/benaadams","html_url":"https://github.com/benaadams","followers_url":"https://api.github.com/users/benaadams/followers","following_url":"https://api.github.com/users/benaadams/following{/other_user}","gists_url":"https://api.github.com/users/benaadams/gists{/gist_id}","starred_url":"https://api.github.com/users/benaadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benaadams/subscriptions","organizations_url":"https://api.github.com/users/benaadams/orgs","repos_url":"https://api.github.com/users/benaadams/repos","events_url":"https://api.github.com/users/benaadams/events{/privacy}","received_events_url":"https://api.github.com/users/benaadams/received_events","type":"User","site_admin":false},"body":"As comparable example of completed Task, aspnet's use is as follows https://github.com/aspnet/Common/blob/dev/shared/Microsoft.Extensions.TaskCache.Sources/TaskCache.cs#L8-L22","created_at":"2017-01-01T14:59:12Z","updated_at":"2017-01-01T14:59:12Z","html_url":"https://github.com/JamesNK/Newtonsoft.Json/pull/1122#discussion_r94285000","pull_request_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/1122","_links":{"self":{"href":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/comments/94285000"},"html":{"href":"https://github.com/JamesNK/Newtonsoft.Json/pull/1122#discussion_r94285000"},"pull_request":{"href":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/1122"}}},"pull_request":{"url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/1122","id":99797621,"html_url":"https://github.com/JamesNK/Newtonsoft.Json/pull/1122","diff_url":"https://github.com/JamesNK/Newtonsoft.Json/pull/1122.diff","patch_url":"https://github.com/JamesNK/Newtonsoft.Json/pull/1122.patch","issue_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1122","number":1122,"state":"open","locked":false,"title":"Asynchronous methods in readers and writers.","user":{"login":"JonHanna","id":1253369,"avatar_url":"https://avatars.githubusercontent.com/u/1253369?v=3","gravatar_id":"","url":"https://api.github.com/users/JonHanna","html_url":"https://github.com/JonHanna","followers_url":"https://api.github.com/users/JonHanna/followers","following_url":"https://api.github.com/users/JonHanna/following{/other_user}","gists_url":"https://api.github.com/users/JonHanna/gists{/gist_id}","starred_url":"https://api.github.com/users/JonHanna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonHanna/subscriptions","organizations_url":"https://api.github.com/users/JonHanna/orgs","repos_url":"https://api.github.com/users/JonHanna/repos","events_url":"https://api.github.com/users/JonHanna/events{/privacy}","received_events_url":"https://api.github.com/users/JonHanna/received_events","type":"User","site_admin":false},"body":"Contributes to #650\r\n\r\nExtracted from #1119 but only covering the async methods on `JsonReader` and `JsonWriter` and implementation for `JsonTextReader` and `JsonTextWriter`.","created_at":"2016-12-31T04:43:33Z","updated_at":"2017-01-01T14:59:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2c5fb163e28565b556b829aeb0b632ea0b381e89","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/1122/commits","review_comments_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/1122/comments","review_comment_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1122/comments","statuses_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/statuses/3809b8d4317c5a629b5e3f6aec9c8b5ee70e74c1","head":{"label":"JonHanna:async_reader_writer","ref":"async_reader_writer","sha":"3809b8d4317c5a629b5e3f6aec9c8b5ee70e74c1","user":{"login":"JonHanna","id":1253369,"avatar_url":"https://avatars.githubusercontent.com/u/1253369?v=3","gravatar_id":"","url":"https://api.github.com/users/JonHanna","html_url":"https://github.com/JonHanna","followers_url":"https://api.github.com/users/JonHanna/followers","following_url":"https://api.github.com/users/JonHanna/following{/other_user}","gists_url":"https://api.github.com/users/JonHanna/gists{/gist_id}","starred_url":"https://api.github.com/users/JonHanna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonHanna/subscriptions","organizations_url":"https://api.github.com/users/JonHanna/orgs","repos_url":"https://api.github.com/users/JonHanna/repos","events_url":"https://api.github.com/users/JonHanna/events{/privacy}","received_events_url":"https://api.github.com/users/JonHanna/received_events","type":"User","site_admin":false},"repo":{"id":76658884,"name":"Newtonsoft.Json","full_name":"JonHanna/Newtonsoft.Json","owner":{"login":"JonHanna","id":1253369,"avatar_url":"https://avatars.githubusercontent.com/u/1253369?v=3","gravatar_id":"","url":"https://api.github.com/users/JonHanna","html_url":"https://github.com/JonHanna","followers_url":"https://api.github.com/users/JonHanna/followers","following_url":"https://api.github.com/users/JonHanna/following{/other_user}","gists_url":"https://api.github.com/users/JonHanna/gists{/gist_id}","starred_url":"https://api.github.com/users/JonHanna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonHanna/subscriptions","organizations_url":"https://api.github.com/users/JonHanna/orgs","repos_url":"https://api.github.com/users/JonHanna/repos","events_url":"https://api.github.com/users/JonHanna/events{/privacy}","received_events_url":"https://api.github.com/users/JonHanna/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JonHanna/Newtonsoft.Json","description":"Json.NET is a popular high-performance JSON framework for .NET","fork":true,"url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json","forks_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/forks","keys_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/teams","hooks_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/hooks","issue_events_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/issues/events{/number}","events_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/events","assignees_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/assignees{/user}","branches_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/branches{/branch}","tags_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/tags","blobs_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/git/refs{/sha}","trees_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/statuses/{sha}","languages_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/languages","stargazers_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/stargazers","contributors_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/contributors","subscribers_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/subscribers","subscription_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/subscription","commits_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/commits{/sha}","git_commits_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/git/commits{/sha}","comments_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/comments{/number}","issue_comment_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/issues/comments{/number}","contents_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/contents/{+path}","compare_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/merges","archive_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/downloads","issues_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/issues{/number}","pulls_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/pulls{/number}","milestones_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/milestones{/number}","notifications_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/labels{/name}","releases_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/releases{/id}","deployments_url":"https://api.github.com/repos/JonHanna/Newtonsoft.Json/deployments","created_at":"2016-12-16T14:14:12Z","updated_at":"2016-12-16T14:14:15Z","pushed_at":"2017-01-01T03:26:16Z","git_url":"git://github.com/JonHanna/Newtonsoft.Json.git","ssh_url":"git@github.com:JonHanna/Newtonsoft.Json.git","clone_url":"https://github.com/JonHanna/Newtonsoft.Json.git","svn_url":"https://github.com/JonHanna/Newtonsoft.Json","homepage":"http://www.newtonsoft.com/json","size":23232,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"JamesNK:master","ref":"master","sha":"0c24088279e37e126c269ffb8bc36d5aa564dae5","user":{"login":"JamesNK","id":303201,"avatar_url":"https://avatars.githubusercontent.com/u/303201?v=3","gravatar_id":"","url":"https://api.github.com/users/JamesNK","html_url":"https://github.com/JamesNK","followers_url":"https://api.github.com/users/JamesNK/followers","following_url":"https://api.github.com/users/JamesNK/following{/other_user}","gists_url":"https://api.github.com/users/JamesNK/gists{/gist_id}","starred_url":"https://api.github.com/users/JamesNK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JamesNK/subscriptions","organizations_url":"https://api.github.com/users/JamesNK/orgs","repos_url":"https://api.github.com/users/JamesNK/repos","events_url":"https://api.github.com/users/JamesNK/events{/privacy}","received_events_url":"https://api.github.com/users/JamesNK/received_events","type":"User","site_admin":false},"repo":{"id":3476845,"name":"Newtonsoft.Json","full_name":"JamesNK/Newtonsoft.Json","owner":{"login":"JamesNK","id":303201,"avatar_url":"https://avatars.githubusercontent.com/u/303201?v=3","gravatar_id":"","url":"https://api.github.com/users/JamesNK","html_url":"https://github.com/JamesNK","followers_url":"https://api.github.com/users/JamesNK/followers","following_url":"https://api.github.com/users/JamesNK/following{/other_user}","gists_url":"https://api.github.com/users/JamesNK/gists{/gist_id}","starred_url":"https://api.github.com/users/JamesNK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JamesNK/subscriptions","organizations_url":"https://api.github.com/users/JamesNK/orgs","repos_url":"https://api.github.com/users/JamesNK/repos","events_url":"https://api.github.com/users/JamesNK/events{/privacy}","received_events_url":"https://api.github.com/users/JamesNK/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JamesNK/Newtonsoft.Json","description":"Json.NET is a popular high-performance JSON framework for .NET","fork":false,"url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json","forks_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/forks","keys_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/teams","hooks_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/hooks","issue_events_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/events{/number}","events_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/events","assignees_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/assignees{/user}","branches_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/branches{/branch}","tags_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/tags","blobs_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/git/refs{/sha}","trees_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/statuses/{sha}","languages_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/languages","stargazers_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/stargazers","contributors_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/contributors","subscribers_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/subscribers","subscription_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/subscription","commits_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/commits{/sha}","git_commits_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/git/commits{/sha}","comments_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/comments{/number}","issue_comment_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/comments{/number}","contents_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/contents/{+path}","compare_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/merges","archive_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/downloads","issues_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues{/number}","pulls_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls{/number}","milestones_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/milestones{/number}","notifications_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/labels{/name}","releases_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/releases{/id}","deployments_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/deployments","created_at":"2012-02-18T07:30:28Z","updated_at":"2017-01-01T07:35:14Z","pushed_at":"2017-01-01T02:06:07Z","git_url":"git://github.com/JamesNK/Newtonsoft.Json.git","ssh_url":"git@github.com:JamesNK/Newtonsoft.Json.git","clone_url":"https://github.com/JamesNK/Newtonsoft.Json.git","svn_url":"https://github.com/JamesNK/Newtonsoft.Json","homepage":"http://www.newtonsoft.com/json","size":23020,"stargazers_count":3747,"watchers_count":3747,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1533,"mirror_url":null,"open_issues_count":93,"forks":1533,"open_issues":93,"watchers":3747,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/1122"},"html":{"href":"https://github.com/JamesNK/Newtonsoft.Json/pull/1122"},"issue":{"href":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1122"},"comments":{"href":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1122/comments"},"review_comments":{"href":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/1122/comments"},"review_comment":{"href":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/pulls/1122/commits"},"statuses":{"href":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/statuses/3809b8d4317c5a629b5e3f6aec9c8b5ee70e74c1"}}}}
{"actor":{"display_login":"benaadams"}}