{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/8142","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/8142/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/8142/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/8142/events","html_url":"https://github.com/dotnet/corefx/issues/8142","id":151602264,"number":8142,"title":"Add a way to wait for a Task without throwing and without allocating","user":{"login":"GSPP","id":12032350,"avatar_url":"https://avatars.githubusercontent.com/u/12032350?v=3","gravatar_id":"","url":"https://api.github.com/users/GSPP","html_url":"https://github.com/GSPP","followers_url":"https://api.github.com/users/GSPP/followers","following_url":"https://api.github.com/users/GSPP/following{/other_user}","gists_url":"https://api.github.com/users/GSPP/gists{/gist_id}","starred_url":"https://api.github.com/users/GSPP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GSPP/subscriptions","organizations_url":"https://api.github.com/users/GSPP/orgs","repos_url":"https://api.github.com/users/GSPP/repos","events_url":"https://api.github.com/users/GSPP/events{/privacy}","received_events_url":"https://api.github.com/users/GSPP/received_events","type":"User","site_admin":false},"labels":[{"id":153714228,"url":"https://api.github.com/repos/dotnet/corefx/labels/api-needs-work","name":"api-needs-work","color":"207de5","default":false},{"id":175425490,"url":"https://api.github.com/repos/dotnet/corefx/labels/area-System.Threading","name":"area-System.Threading","color":"d4c5f9","default":false},{"id":145399958,"url":"https://api.github.com/repos/dotnet/corefx/labels/up%20for%20grabs","name":"up for grabs","color":"159818","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/dotnet/corefx/milestones/5","html_url":"https://github.com/dotnet/corefx/milestone/5","labels_url":"https://api.github.com/repos/dotnet/corefx/milestones/5/labels","id":1328080,"number":5,"title":"Future","description":"Milestone tracking the issues triaged for an unspecified future release","creator":{"login":"joshfree","id":1302850,"avatar_url":"https://avatars.githubusercontent.com/u/1302850?v=3","gravatar_id":"","url":"https://api.github.com/users/joshfree","html_url":"https://github.com/joshfree","followers_url":"https://api.github.com/users/joshfree/followers","following_url":"https://api.github.com/users/joshfree/following{/other_user}","gists_url":"https://api.github.com/users/joshfree/gists{/gist_id}","starred_url":"https://api.github.com/users/joshfree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshfree/subscriptions","organizations_url":"https://api.github.com/users/joshfree/orgs","repos_url":"https://api.github.com/users/joshfree/repos","events_url":"https://api.github.com/users/joshfree/events{/privacy}","received_events_url":"https://api.github.com/users/joshfree/received_events","type":"User","site_admin":false},"open_issues":724,"closed_issues":6,"state":"open","created_at":"2015-09-29T00:25:45Z","updated_at":"2016-12-26T23:22:11Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2016-04-28T10:22:52Z","updated_at":"2016-12-27T18:28:11Z","closed_at":null,"body":"At the moment there does not seem to be ay direct API that you can use to wait for a task to complete without throwing in case the task completes cancelled or faulted.\n\nThis forces using exceptions for control flow:\n\n```\ntry {\n task.Wait();\n}\ncatch (AggEx) { } //Do nothing.\n```\n\nThis is ugly and _very_ slow. Exceptions seem to cost ~0.1ms of CPU time to process.\n\nSo if you are writing a port scanner using async IO you will find that you cannot scan more that 10k ports per second because the CPU is pegged from exception processing(!). Also, I don't know if exceptions scale across CPUs. I know that `ExceptionDispatchInfo` uses a global lock internally. So at least some of the processing does not scale at all.\n\nIt might not be too common to have many faulted tasks. But it is more likely to rely on a greater number of cancelled tasks.\n\nI know of two workarounds:\n\n```\nTask.WhenAny(task); //params overload\ntask.CW(() => { }, ExecuteSynchronously).Wait();\n```\n\nBoth allocate, add overhead and both make it unclear what you want to achieve.\n\nPlease add a simpler and faster way to wait for a task to complete regardless of the terminal state it ends up in.\n\nThe same problem exists with `await`. There is no direct way to wait for completion without throwing. Maybe `ConfigureAwait` can be extended with an `AwaitOptions` enum that has the values `IgnoreContext, NoThrow`.\n"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/269363828","html_url":"https://github.com/dotnet/corefx/issues/8142#issuecomment-269363828","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/8142","id":269363828,"user":{"login":"danmosemsft","id":6385855,"avatar_url":"https://avatars.githubusercontent.com/u/6385855?v=3","gravatar_id":"","url":"https://api.github.com/users/danmosemsft","html_url":"https://github.com/danmosemsft","followers_url":"https://api.github.com/users/danmosemsft/followers","following_url":"https://api.github.com/users/danmosemsft/following{/other_user}","gists_url":"https://api.github.com/users/danmosemsft/gists{/gist_id}","starred_url":"https://api.github.com/users/danmosemsft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danmosemsft/subscriptions","organizations_url":"https://api.github.com/users/danmosemsft/orgs","repos_url":"https://api.github.com/users/danmosemsft/repos","events_url":"https://api.github.com/users/danmosemsft/events{/privacy}","received_events_url":"https://api.github.com/users/danmosemsft/received_events","type":"User","site_admin":false},"created_at":"2016-12-27T18:28:11Z","updated_at":"2016-12-27T18:28:11Z","body":"@GSPP do you want to complete formal API proposal then we can review formally?\r\n\r\nDocs on the [API review process](https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/api-review-process.md) and see [Jon's API request](https://github.com/dotnet/corefx/issues/4547) for a great example of a strong proposal. The more concrete the proposal is (e.g. has examples of usage, real-world scenarios, fleshed out API), the more discussion it will start and the better the chances of us being able to push the addition through the review process."}}
{"actor":{"display_login":"danmosemsft"}}