{"action":"created","issue":{"url":"https://api.github.com/repos/StephenCleary/AsyncEx/issues/23","labels_url":"https://api.github.com/repos/StephenCleary/AsyncEx/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/StephenCleary/AsyncEx/issues/23/comments","events_url":"https://api.github.com/repos/StephenCleary/AsyncEx/issues/23/events","html_url":"https://github.com/StephenCleary/AsyncEx/issues/23","id":91014704,"number":23,"title":"AsyncManualResetEvent WaitAsync no cancellation support","user":{"login":"magitech","id":718288,"avatar_url":"https://avatars.githubusercontent.com/u/718288?v=3","gravatar_id":"","url":"https://api.github.com/users/magitech","html_url":"https://github.com/magitech","followers_url":"https://api.github.com/users/magitech/followers","following_url":"https://api.github.com/users/magitech/following{/other_user}","gists_url":"https://api.github.com/users/magitech/gists{/gist_id}","starred_url":"https://api.github.com/users/magitech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magitech/subscriptions","organizations_url":"https://api.github.com/users/magitech/orgs","repos_url":"https://api.github.com/users/magitech/repos","events_url":"https://api.github.com/users/magitech/events{/privacy}","received_events_url":"https://api.github.com/users/magitech/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-25T16:38:08Z","updated_at":"2015-06-25T16:51:31Z","closed_at":"2015-06-25T16:51:31Z","body":"What is the reasoning behind AsyncManualResetEvent WaitAsync method not supporting a CancellationToken? The documentation state \"WaitAsync does not have explicit CancellationToken support because there are no state changes when a wait is satisfied.\"[1](https://github.com/StephenCleary/AsyncEx/wiki/AsyncManualResetEvent#design-notes) however if the AsyncManualResetEvent is never set this Task will not complete. \r\n\r\nWhat is the guidance for accomplishing this behavior? The only solution I can come up with is to register a continuation on the cancellation token to set the AsyncManualResetEvent when cancelled. After the WaitAsync throw the cancellation exception."},"comment":{"url":"https://api.github.com/repos/StephenCleary/AsyncEx/issues/comments/115322046","html_url":"https://github.com/StephenCleary/AsyncEx/issues/23#issuecomment-115322046","issue_url":"https://api.github.com/repos/StephenCleary/AsyncEx/issues/23","id":115322046,"user":{"login":"StephenCleary","id":900597,"avatar_url":"https://avatars.githubusercontent.com/u/900597?v=3","gravatar_id":"","url":"https://api.github.com/users/StephenCleary","html_url":"https://github.com/StephenCleary","followers_url":"https://api.github.com/users/StephenCleary/followers","following_url":"https://api.github.com/users/StephenCleary/following{/other_user}","gists_url":"https://api.github.com/users/StephenCleary/gists{/gist_id}","starred_url":"https://api.github.com/users/StephenCleary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StephenCleary/subscriptions","organizations_url":"https://api.github.com/users/StephenCleary/orgs","repos_url":"https://api.github.com/users/StephenCleary/repos","events_url":"https://api.github.com/users/StephenCleary/events{/privacy}","received_events_url":"https://api.github.com/users/StephenCleary/received_events","type":"User","site_admin":false},"created_at":"2015-06-25T16:51:31Z","updated_at":"2015-06-25T16:51:31Z","body":"Currently, there's only built-in `CancellationToken` support if the cancellation actually means something to the synchronization primitive (i.e., prevents a state change). In the case of AMRE, cancelling a `WaitAsync` would only cancel the *wait*; it would have no effect on state changes.\r\n\r\nThat said, for the .NET Core API redesign, I've already added `CancellationToken` overloads to everything, even if they would only cancel the wait.\r\n\r\nWith the current version, the best way to cancel a `WaitAsync` (or any other `await`) is to use `CancellationTokenTaskSource`:\r\n\r\n    using (var ctts = cancellationToken.ToCancellationTokenTaskSource())\r\n    {\r\n      await Task.WhenAny(amre.WaitAsync(), ctts.Task);\r\n    }"}}