alastairtree / LazyCache

An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
https://nuget.org/packages/LazyCache
MIT License
1.71k stars 159 forks source link

In GetOrAddAsync replace Thread.Yield by await Task.Delay(1)? #197

Open szmcdull opened 3 weeks ago

szmcdull commented 3 weeks ago

[Use the Thumbs Up reaction to vote for this feature, and please avoid adding comments like "+1" as they create noise for others watching the issue.]

Is your feature request related to a problem? Please describe. Thread.Yield in a loop will lock down the whole thread, so no other async routines can run on the trhead. This may lead to problems where many async routines are running or being created.

Describe the solution you'd like Simply replace Thread.Yield by await Task.Delay(1) or something alike.

Additional context I'm specifically concern because I'm using a single-threaded async model. Locking the thread will dead lock.