{"action":"created","comment":{"url":"https://api.github.com/repos/jbogard/MediatR/pulls/comments/77244207","id":77244207,"diff_hunk":"@@ -73,20 +88,65 @@ public void Publish(INotification notification)\n \r\n         public Task PublishAsync(IAsyncNotification notification)\r\n         {\r\n-            var notificationHandlers = GetNotificationHandlers(notification)\r\n+            var notificationHandlers = GetNotificationHandlers(notification);\r\n+\r\n+            if (_publishOption == PublishAsyncOptions.Parallel)\r\n+            {\r\n+                return PublishParallelAsync(notification, notificationHandlers);\r\n+            }\r\n+            else\r\n+            {\r\n+                return PublishSequentialAsync(notification, notificationHandlers);\r\n+            }\r\n+        }\r\n+\r\n+        public Task PublishAsync(ICancellableAsyncNotification notification, CancellationToken cancellationToken)\r\n+        {\r\n+            var notificationHandlers = GetNotificationHandlers(notification);\r\n+\r\n+            if (_publishOption == PublishAsyncOptions.Parallel)\r\n+            {\r\n+                return PublishParallelAsync(notification, cancellationToken, notificationHandlers);\r\n+            }\r\n+            else\r\n+            {\r\n+                return PublishSequentialAsync(notification, cancellationToken, notificationHandlers);\r\n+            }\r\n+        }\r\n+\r\n+        private async Task PublishSequentialAsync(IAsyncNotification notification, IEnumerable<AsyncNotificationHandlerWrapper> notificationHandlers)\r\n+        {\r\n+            foreach (var handler in notificationHandlers)\r\n+            {\r\n+                await handler.Handle(notification);\r\n+            }\r\n+        }\r\n+\r\n+        private Task PublishParallelAsync(IAsyncNotification notification, IEnumerable<AsyncNotificationHandlerWrapper> notificationHandlers)\r\n+        {\r\n+            var tasks = notificationHandlers\r\n                 .Select(handler => handler.Handle(notification))\r\n                 .ToArray();\r\n \r\n-            return Task.WhenAll(notificationHandlers);\r\n+            return Task.WhenAll(tasks);\r\n         }\r\n \r\n-        public Task PublishAsync(ICancellableAsyncNotification notification, CancellationToken cancellationToken)\r\n+        private Task PublishParallelAsync(ICancellableAsyncNotification notification, CancellationToken cancellationToken,\r\n+            IEnumerable<CancellableAsyncNotificationHandlerWrapper> notificationHandlers)\r\n         {\r\n-            var notificationHandlers = GetNotificationHandlers(notification)\r\n+            var tasks = notificationHandlers\r\n                 .Select(handler => handler.Handle(notification, cancellationToken))\r\n                 .ToArray();\r","path":"src/MediatR/Mediator.cs","position":90,"original_position":90,"commit_id":"9ff0f60c17037106b405b082bd94615fdc31e644","original_commit_id":"9ff0f60c17037106b405b082bd94615fdc31e644","user":{"login":"abatishchev","id":351644,"avatar_url":"https://avatars.githubusercontent.com/u/351644?v=3","gravatar_id":"","url":"https://api.github.com/users/abatishchev","html_url":"https://github.com/abatishchev","followers_url":"https://api.github.com/users/abatishchev/followers","following_url":"https://api.github.com/users/abatishchev/following{/other_user}","gists_url":"https://api.github.com/users/abatishchev/gists{/gist_id}","starred_url":"https://api.github.com/users/abatishchev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abatishchev/subscriptions","organizations_url":"https://api.github.com/users/abatishchev/orgs","repos_url":"https://api.github.com/users/abatishchev/repos","events_url":"https://api.github.com/users/abatishchev/events{/privacy}","received_events_url":"https://api.github.com/users/abatishchev/received_events","type":"User","site_admin":false},"body":"False or true, anyway let's be more friendly, right? I'm basing my statement on my experience that calling ToArray() kick-offs these tasks before they're reaching Task.WhenAll() what doesn't help much during debugging. Thanks for pointing out to the source code. But still I'd pass IEnumerable directly and let TPL do its work.","created_at":"2016-09-01T20:08:47Z","updated_at":"2016-09-01T20:08:47Z","html_url":"https://github.com/jbogard/MediatR/pull/101#discussion_r77244207","pull_request_url":"https://api.github.com/repos/jbogard/MediatR/pulls/101","_links":{"self":{"href":"https://api.github.com/repos/jbogard/MediatR/pulls/comments/77244207"},"html":{"href":"https://github.com/jbogard/MediatR/pull/101#discussion_r77244207"},"pull_request":{"href":"https://api.github.com/repos/jbogard/MediatR/pulls/101"}}},"pull_request":{"url":"https://api.github.com/repos/jbogard/MediatR/pulls/101","id":83661627,"html_url":"https://github.com/jbogard/MediatR/pull/101","diff_url":"https://github.com/jbogard/MediatR/pull/101.diff","patch_url":"https://github.com/jbogard/MediatR/pull/101.patch","issue_url":"https://api.github.com/repos/jbogard/MediatR/issues/101","number":101,"state":"open","locked":false,"title":"Added option to enable PublishAsync to invoke handlers sequentially","user":{"login":"samueldjack","id":837684,"avatar_url":"https://avatars.githubusercontent.com/u/837684?v=3","gravatar_id":"","url":"https://api.github.com/users/samueldjack","html_url":"https://github.com/samueldjack","followers_url":"https://api.github.com/users/samueldjack/followers","following_url":"https://api.github.com/users/samueldjack/following{/other_user}","gists_url":"https://api.github.com/users/samueldjack/gists{/gist_id}","starred_url":"https://api.github.com/users/samueldjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samueldjack/subscriptions","organizations_url":"https://api.github.com/users/samueldjack/orgs","repos_url":"https://api.github.com/users/samueldjack/repos","events_url":"https://api.github.com/users/samueldjack/events{/privacy}","received_events_url":"https://api.github.com/users/samueldjack/received_events","type":"User","site_admin":false},"body":"This helps to address #98 by adding a configuration option to enable invoking async notification handlers sequentially rather than in parallel.","created_at":"2016-09-01T16:06:59Z","updated_at":"2016-09-01T20:08:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d60cd5bf7f08bb120540c728d5b77051750a1f4b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/jbogard/MediatR/pulls/101/commits","review_comments_url":"https://api.github.com/repos/jbogard/MediatR/pulls/101/comments","review_comment_url":"https://api.github.com/repos/jbogard/MediatR/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jbogard/MediatR/issues/101/comments","statuses_url":"https://api.github.com/repos/jbogard/MediatR/statuses/9ff0f60c17037106b405b082bd94615fdc31e644","head":{"label":"samueldjack:master","ref":"master","sha":"9ff0f60c17037106b405b082bd94615fdc31e644","user":{"login":"samueldjack","id":837684,"avatar_url":"https://avatars.githubusercontent.com/u/837684?v=3","gravatar_id":"","url":"https://api.github.com/users/samueldjack","html_url":"https://github.com/samueldjack","followers_url":"https://api.github.com/users/samueldjack/followers","following_url":"https://api.github.com/users/samueldjack/following{/other_user}","gists_url":"https://api.github.com/users/samueldjack/gists{/gist_id}","starred_url":"https://api.github.com/users/samueldjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samueldjack/subscriptions","organizations_url":"https://api.github.com/users/samueldjack/orgs","repos_url":"https://api.github.com/users/samueldjack/repos","events_url":"https://api.github.com/users/samueldjack/events{/privacy}","received_events_url":"https://api.github.com/users/samueldjack/received_events","type":"User","site_admin":false},"repo":{"id":67135834,"name":"MediatR","full_name":"samueldjack/MediatR","owner":{"login":"samueldjack","id":837684,"avatar_url":"https://avatars.githubusercontent.com/u/837684?v=3","gravatar_id":"","url":"https://api.github.com/users/samueldjack","html_url":"https://github.com/samueldjack","followers_url":"https://api.github.com/users/samueldjack/followers","following_url":"https://api.github.com/users/samueldjack/following{/other_user}","gists_url":"https://api.github.com/users/samueldjack/gists{/gist_id}","starred_url":"https://api.github.com/users/samueldjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samueldjack/subscriptions","organizations_url":"https://api.github.com/users/samueldjack/orgs","repos_url":"https://api.github.com/users/samueldjack/repos","events_url":"https://api.github.com/users/samueldjack/events{/privacy}","received_events_url":"https://api.github.com/users/samueldjack/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/samueldjack/MediatR","description":"Simple, unambitious mediator implementation in .NET","fork":true,"url":"https://api.github.com/repos/samueldjack/MediatR","forks_url":"https://api.github.com/repos/samueldjack/MediatR/forks","keys_url":"https://api.github.com/repos/samueldjack/MediatR/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samueldjack/MediatR/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samueldjack/MediatR/teams","hooks_url":"https://api.github.com/repos/samueldjack/MediatR/hooks","issue_events_url":"https://api.github.com/repos/samueldjack/MediatR/issues/events{/number}","events_url":"https://api.github.com/repos/samueldjack/MediatR/events","assignees_url":"https://api.github.com/repos/samueldjack/MediatR/assignees{/user}","branches_url":"https://api.github.com/repos/samueldjack/MediatR/branches{/branch}","tags_url":"https://api.github.com/repos/samueldjack/MediatR/tags","blobs_url":"https://api.github.com/repos/samueldjack/MediatR/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samueldjack/MediatR/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samueldjack/MediatR/git/refs{/sha}","trees_url":"https://api.github.com/repos/samueldjack/MediatR/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samueldjack/MediatR/statuses/{sha}","languages_url":"https://api.github.com/repos/samueldjack/MediatR/languages","stargazers_url":"https://api.github.com/repos/samueldjack/MediatR/stargazers","contributors_url":"https://api.github.com/repos/samueldjack/MediatR/contributors","subscribers_url":"https://api.github.com/repos/samueldjack/MediatR/subscribers","subscription_url":"https://api.github.com/repos/samueldjack/MediatR/subscription","commits_url":"https://api.github.com/repos/samueldjack/MediatR/commits{/sha}","git_commits_url":"https://api.github.com/repos/samueldjack/MediatR/git/commits{/sha}","comments_url":"https://api.github.com/repos/samueldjack/MediatR/comments{/number}","issue_comment_url":"https://api.github.com/repos/samueldjack/MediatR/issues/comments{/number}","contents_url":"https://api.github.com/repos/samueldjack/MediatR/contents/{+path}","compare_url":"https://api.github.com/repos/samueldjack/MediatR/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samueldjack/MediatR/merges","archive_url":"https://api.github.com/repos/samueldjack/MediatR/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samueldjack/MediatR/downloads","issues_url":"https://api.github.com/repos/samueldjack/MediatR/issues{/number}","pulls_url":"https://api.github.com/repos/samueldjack/MediatR/pulls{/number}","milestones_url":"https://api.github.com/repos/samueldjack/MediatR/milestones{/number}","notifications_url":"https://api.github.com/repos/samueldjack/MediatR/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samueldjack/MediatR/labels{/name}","releases_url":"https://api.github.com/repos/samueldjack/MediatR/releases{/id}","deployments_url":"https://api.github.com/repos/samueldjack/MediatR/deployments","created_at":"2016-09-01T13:56:23Z","updated_at":"2016-09-01T13:56:24Z","pushed_at":"2016-09-01T16:03:15Z","git_url":"git://github.com/samueldjack/MediatR.git","ssh_url":"git@github.com:samueldjack/MediatR.git","clone_url":"https://github.com/samueldjack/MediatR.git","svn_url":"https://github.com/samueldjack/MediatR","homepage":"","size":3978,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"jbogard:master","ref":"master","sha":"9bc53ed38b4eeeb90f78d324f39d8ccb9e0738c0","user":{"login":"jbogard","id":104498,"avatar_url":"https://avatars.githubusercontent.com/u/104498?v=3","gravatar_id":"","url":"https://api.github.com/users/jbogard","html_url":"https://github.com/jbogard","followers_url":"https://api.github.com/users/jbogard/followers","following_url":"https://api.github.com/users/jbogard/following{/other_user}","gists_url":"https://api.github.com/users/jbogard/gists{/gist_id}","starred_url":"https://api.github.com/users/jbogard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbogard/subscriptions","organizations_url":"https://api.github.com/users/jbogard/orgs","repos_url":"https://api.github.com/users/jbogard/repos","events_url":"https://api.github.com/users/jbogard/events{/privacy}","received_events_url":"https://api.github.com/users/jbogard/received_events","type":"User","site_admin":false},"repo":{"id":17369361,"name":"MediatR","full_name":"jbogard/MediatR","owner":{"login":"jbogard","id":104498,"avatar_url":"https://avatars.githubusercontent.com/u/104498?v=3","gravatar_id":"","url":"https://api.github.com/users/jbogard","html_url":"https://github.com/jbogard","followers_url":"https://api.github.com/users/jbogard/followers","following_url":"https://api.github.com/users/jbogard/following{/other_user}","gists_url":"https://api.github.com/users/jbogard/gists{/gist_id}","starred_url":"https://api.github.com/users/jbogard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbogard/subscriptions","organizations_url":"https://api.github.com/users/jbogard/orgs","repos_url":"https://api.github.com/users/jbogard/repos","events_url":"https://api.github.com/users/jbogard/events{/privacy}","received_events_url":"https://api.github.com/users/jbogard/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jbogard/MediatR","description":"Simple, unambitious mediator implementation in .NET","fork":false,"url":"https://api.github.com/repos/jbogard/MediatR","forks_url":"https://api.github.com/repos/jbogard/MediatR/forks","keys_url":"https://api.github.com/repos/jbogard/MediatR/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jbogard/MediatR/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jbogard/MediatR/teams","hooks_url":"https://api.github.com/repos/jbogard/MediatR/hooks","issue_events_url":"https://api.github.com/repos/jbogard/MediatR/issues/events{/number}","events_url":"https://api.github.com/repos/jbogard/MediatR/events","assignees_url":"https://api.github.com/repos/jbogard/MediatR/assignees{/user}","branches_url":"https://api.github.com/repos/jbogard/MediatR/branches{/branch}","tags_url":"https://api.github.com/repos/jbogard/MediatR/tags","blobs_url":"https://api.github.com/repos/jbogard/MediatR/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jbogard/MediatR/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jbogard/MediatR/git/refs{/sha}","trees_url":"https://api.github.com/repos/jbogard/MediatR/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jbogard/MediatR/statuses/{sha}","languages_url":"https://api.github.com/repos/jbogard/MediatR/languages","stargazers_url":"https://api.github.com/repos/jbogard/MediatR/stargazers","contributors_url":"https://api.github.com/repos/jbogard/MediatR/contributors","subscribers_url":"https://api.github.com/repos/jbogard/MediatR/subscribers","subscription_url":"https://api.github.com/repos/jbogard/MediatR/subscription","commits_url":"https://api.github.com/repos/jbogard/MediatR/commits{/sha}","git_commits_url":"https://api.github.com/repos/jbogard/MediatR/git/commits{/sha}","comments_url":"https://api.github.com/repos/jbogard/MediatR/comments{/number}","issue_comment_url":"https://api.github.com/repos/jbogard/MediatR/issues/comments{/number}","contents_url":"https://api.github.com/repos/jbogard/MediatR/contents/{+path}","compare_url":"https://api.github.com/repos/jbogard/MediatR/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jbogard/MediatR/merges","archive_url":"https://api.github.com/repos/jbogard/MediatR/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jbogard/MediatR/downloads","issues_url":"https://api.github.com/repos/jbogard/MediatR/issues{/number}","pulls_url":"https://api.github.com/repos/jbogard/MediatR/pulls{/number}","milestones_url":"https://api.github.com/repos/jbogard/MediatR/milestones{/number}","notifications_url":"https://api.github.com/repos/jbogard/MediatR/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jbogard/MediatR/labels{/name}","releases_url":"https://api.github.com/repos/jbogard/MediatR/releases{/id}","deployments_url":"https://api.github.com/repos/jbogard/MediatR/deployments","created_at":"2014-03-03T15:01:22Z","updated_at":"2016-09-01T18:47:29Z","pushed_at":"2016-09-01T16:07:00Z","git_url":"git://github.com/jbogard/MediatR.git","ssh_url":"git@github.com:jbogard/MediatR.git","clone_url":"https://github.com/jbogard/MediatR.git","svn_url":"https://github.com/jbogard/MediatR","homepage":"","size":4064,"stargazers_count":650,"watchers_count":650,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":115,"mirror_url":null,"open_issues_count":26,"forks":115,"open_issues":26,"watchers":650,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jbogard/MediatR/pulls/101"},"html":{"href":"https://github.com/jbogard/MediatR/pull/101"},"issue":{"href":"https://api.github.com/repos/jbogard/MediatR/issues/101"},"comments":{"href":"https://api.github.com/repos/jbogard/MediatR/issues/101/comments"},"review_comments":{"href":"https://api.github.com/repos/jbogard/MediatR/pulls/101/comments"},"review_comment":{"href":"https://api.github.com/repos/jbogard/MediatR/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jbogard/MediatR/pulls/101/commits"},"statuses":{"href":"https://api.github.com/repos/jbogard/MediatR/statuses/9ff0f60c17037106b405b082bd94615fdc31e644"}}}}
{"actor":{"display_login":"abatishchev"}}