StephenCleary / AsyncEx

A helper library for async/await.
MIT License
3.49k stars 358 forks source link

[Question] Using discard with AsyncLock #277

Closed deastr closed 1 year ago

deastr commented 1 year ago

Hello,

Is this a bad idea? I know Dispose is still called with using a discard but I want to be sure with AsyncLock:

if(..)
{
    using var _ = await asyncLock.LockAsync(token);
    //rest of the if block that needs to be locked
}
StephenCleary commented 1 year ago

Yes, that will work fine.

Personally, I prefer the braces, because it makes the "needs to be locked" code very explicit. But it works just as well without the braces.