-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
[Discussion] Return ValueTask
instead of AwaitableDisposable
?
#265
Comments
Could the |
Yes, it should be possible to use ValueTask from System.Threading.Tasks.Extensions to support older frameworks. Pretty late to the discussion, but this PR as a whole would be pretty interesting to expand on. |
Created a new experimental async lock implementation that supports fast, zero-alloc reentrancy: https://github.com/BalassaMarton/AsyncExtensions |
@BalassaMarton I'm always skeptical of any re-entrant async locks. Does your solution hold up to the problems presented in this article? |
@timcassell look at this example: https://github.com/BalassaMarton/AsyncExtensions?tab=readme-ov-file#example-recursive-async-locking-using-a-token async ValueTask OuterMethod(AsyncLockToken token = default)
{
using (token = await mutex.LockAsync(token))
{
await InnerMethod(token);
}
}
async ValueTask InnerMethod(AsyncLockToken token = default)
{
using (await mutex.LockAsync(token))
{
// ...
}
} I even had a variation where you could name your |
Methods returning
AwaitableDisposable
could returnValueTask
instead.Pros
Cons
ValueTask
.I'll submit an experimental PR just for the sake of discussion.
The text was updated successfully, but these errors were encountered: