{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/5187","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/5187/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/5187/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/5187/events","html_url":"https://github.com/dotnet/roslyn/issues/5187","id":106115811,"number":5187,"title":"[Proposal] Asynchronous switch","user":{"login":"gafter","id":3804346,"avatar_url":"https://avatars.githubusercontent.com/u/3804346?v=3","gravatar_id":"","url":"https://api.github.com/users/gafter","html_url":"https://github.com/gafter","followers_url":"https://api.github.com/users/gafter/followers","following_url":"https://api.github.com/users/gafter/following{/other_user}","gists_url":"https://api.github.com/users/gafter/gists{/gist_id}","starred_url":"https://api.github.com/users/gafter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gafter/subscriptions","organizations_url":"https://api.github.com/users/gafter/orgs","repos_url":"https://api.github.com/users/gafter/repos","events_url":"https://api.github.com/users/gafter/events{/privacy}","received_events_url":"https://api.github.com/users/gafter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Language%20Design","name":"Area-Language Design","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Feature%20Request","name":"Feature Request","color":"fc2929"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Feature%20Specification","name":"Feature Specification","color":"fc2929"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Language-C%23","name":"Language-C#","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/dotnet/roslyn/milestones/8","html_url":"https://github.com/dotnet/roslyn/milestones/C%23%207%20and%20VB%2015","labels_url":"https://api.github.com/repos/dotnet/roslyn/milestones/8/labels","id":962632,"number":8,"title":"C# 7 and VB 15","description":"\r\n\r\n<!---\r\n@huboard:{\"order\":0.375}\r\n-->\r\n","creator":{"login":"gafter","id":3804346,"avatar_url":"https://avatars.githubusercontent.com/u/3804346?v=3","gravatar_id":"","url":"https://api.github.com/users/gafter","html_url":"https://github.com/gafter","followers_url":"https://api.github.com/users/gafter/followers","following_url":"https://api.github.com/users/gafter/following{/other_user}","gists_url":"https://api.github.com/users/gafter/gists{/gist_id}","starred_url":"https://api.github.com/users/gafter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gafter/subscriptions","organizations_url":"https://api.github.com/users/gafter/orgs","repos_url":"https://api.github.com/users/gafter/repos","events_url":"https://api.github.com/users/gafter/events{/privacy}","received_events_url":"https://api.github.com/users/gafter/received_events","type":"User","site_admin":false},"open_issues":54,"closed_issues":5,"state":"open","created_at":"2015-02-02T23:41:34Z","updated_at":"2015-09-12T00:20:28Z","due_on":null,"closed_at":null},"comments":19,"created_at":"2015-09-12T00:20:28Z","updated_at":"2015-09-12T22:23:09Z","closed_at":null,"body":"We propose a new statement form that waits for a number of tasks to complete, and executes a code block corresponding to the first one that completes.\r\n\r\n### Syntax\r\n\r\n> *statement*:\r\n> &nbsp;&nbsp;&nbsp;&nbsp;*select-statement*\r\n> *select-statement*:\r\n> &nbsp;&nbsp;&nbsp;&nbsp;`select` *select-block*\r\n\r\n`select` is a new context-sensitive keyword.\r\n\r\n> *select-block*:\r\n> &nbsp;&nbsp;&nbsp;&nbsp;`{` *select-case-list* *select-default*<sub>opt</sub> `}`\r\n> *select-case-list*:\r\n> &nbsp;&nbsp;&nbsp;&nbsp;*select-case*\r\n> &nbsp;&nbsp;&nbsp;&nbsp;*select-case-list* *select-case*\r\n> *select-case*:\r\n> &nbsp;&nbsp;&nbsp;&nbsp;`case` *type* *identifier* `=` `await` *expression* `:` *block*\r\n> &nbsp;&nbsp;&nbsp;&nbsp;`case` `await` *expression* `:` *block*\r\n> *select-default*:\r\n> &nbsp;&nbsp;&nbsp;&nbsp;`default` `:` *block*\r\n\r\n### Semantics\r\n\r\nIt is an error for a *select-case* to appear where the directly enclosing method is not `async`.\r\n\r\nFor each *select-case*\r\n- The type of the *expression* must be `Task` or some instance of `Task<>`.\r\n- If the type is `Task`, then there is no *identifier* in the *select-case*.\r\n- If the type is `Task<T>` for some type `T`, then the type `T` must be assignable to *type*.\r\n\r\nOne may specify `var` to have the type of the variable inferred.\r\n\r\nAt runtime, the expressions to the right of the `await` keywords in each *select-case* are evaluated, in order. If none of those tasks has completed:\r\n- If there is a *select-default*, its corresponding block is executed, and execution of the *select-case* is done; otherwise\r\n- The enclosing `async` method is suspended until one of the tasks completes.\r\n\r\nThen (if the *select-default* block was not executed), for one of those tasks *t* that has completed:\r\n- If *t* ended in the *canceled* state, an `OperationCanceledException` is thrown.\r\n- if *t* ended in the *faulted* state, its corresponding exception is thrown.\r\n- Otherwise the corresponding *block* is executed.\r\n\r\nWe still need to define the definite-assignment and reachability rules for the *select-statement*.\r\n\r\n### Example\r\n\r\nThanks to @HaloFour \r\n\r\n```cs\r\nselect {\r\n    case string primaryContents = await client.DownloadStringTaskAsync(primaryUri): {\r\n        Console.WriteLine($\"Downloaded contents from primary URI: {primaryContents}\");\r\n    }\r\n    case string secondaryContents = await client.DownloadStringTaskAsync(secondaryUri): {\r\n        Console.WriteLine($\"Downloaded contents from secondary URI: {secondaryContents}\");\r\n    }\r\n    case await Task.Delay(1000): {\r\n        Console.WriteLine(\"Failed to download from either URI within a second.\");\r\n    }\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/139825119","html_url":"https://github.com/dotnet/roslyn/issues/5187#issuecomment-139825119","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/5187","id":139825119,"user":{"login":"AdamSpeight2008","id":900107,"avatar_url":"https://avatars.githubusercontent.com/u/900107?v=3","gravatar_id":"","url":"https://api.github.com/users/AdamSpeight2008","html_url":"https://github.com/AdamSpeight2008","followers_url":"https://api.github.com/users/AdamSpeight2008/followers","following_url":"https://api.github.com/users/AdamSpeight2008/following{/other_user}","gists_url":"https://api.github.com/users/AdamSpeight2008/gists{/gist_id}","starred_url":"https://api.github.com/users/AdamSpeight2008/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AdamSpeight2008/subscriptions","organizations_url":"https://api.github.com/users/AdamSpeight2008/orgs","repos_url":"https://api.github.com/users/AdamSpeight2008/repos","events_url":"https://api.github.com/users/AdamSpeight2008/events{/privacy}","received_events_url":"https://api.github.com/users/AdamSpeight2008/received_events","type":"User","site_admin":false},"created_at":"2015-09-12T22:23:09Z","updated_at":"2015-09-12T22:23:09Z","body":"@gafter I meant `Task.WaitAny` , update the sample. \r\nRead the spec, just say it throws. You still don't know which task, threw the exception.\r\n With a separate collection of tasks at least you can look through them to find the faulted one."}}