dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.67k stars 4.58k forks source link

Make TimeProviderTaskExtensions WaitAsync run continuations synchronously like Delay #104654

Open Snaaio opened 2 weeks ago

Snaaio commented 2 weeks ago

This was already solved for TimeProviderTaskExtensions Delay in #85326 (PR #90489). See the rationale there.

I think this should be fixed for WaitAsync as well, because of the same rationale (and now also for consistency with Delay).

Therefore I propose to change: https://github.com/dotnet/runtime/blob/cd9cc877d157684dd69ccc4d2cabaa60368b1524/src/libraries/Microsoft.Bcl.TimeProvider/src/System/Threading/Tasks/TimeProviderTaskExtensions.cs public WaitAsyncState(CancellationToken cancellationToken) : base(TaskCreationOptions.RunContinuationsAsynchronously) to: public WaitAsyncState(CancellationToken cancellationToken)

Snaaio commented 2 weeks ago

Tagging the people that were already involved in #85326: @egil @tarekgh @stephentoub

tarekgh commented 2 weeks ago

This issue is related to or a duplicate of https://github.com/dotnet/runtime/issues/92264. We previously investigated this and decided against making changes because, while altering it might help in some scenarios, it would cause problems in others.

I suggest closing this issue. If you encounter any problems, we can recommend an appropriate workaround.

@stephentoub let us know what you think.

Snaaio commented 1 week ago

Thanks for the info. Bit of a bummer, but understandable ;-)

Is there a better workaround than having to await Task.Yield() (or even a small delay), preferably one that keeps tests deterministic?

tarekgh commented 1 week ago

What is your failing test? Could you please write your test case here? and why you are not preferring await Task.Yield()? or you are curious to know if there is any other workaround?