Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithTimeout wont stop timed-out tasks #59

Open
pcampbell83 opened this issue Dec 4, 2019 · 1 comment
Open

WithTimeout wont stop timed-out tasks #59

pcampbell83 opened this issue Dec 4, 2019 · 1 comment

Comments

@pcampbell83
Copy link

Hi, looking at the implementation -- won't the net result be that; the task itself will not stop running even if the timeout succeeds first?

Is that intentional?

@mjfreelancing
Copy link
Contributor

I agree. Even if the caller checks the return result against default this is no indication the task timed out because the running task may actually return null if T is a reference type. And yes, if the delay task completes first then the original task will remain running.

The only way to do this correctly is for the caller to use a CancellationTokenSource and have this cancelled if the delay task completes first. It's then up to the caller to handle this situation within their own logic by checking IsCancellationRequested on the CancellationToken.

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/cancel-remaining-async-tasks-after-one-is-complete

https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken.iscancellationrequested?view=netframework-4.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants