Reputation: 31
The following pseudocode may be a little too boiled down, but this is more of a general question
using (var thelock = await redLockFactory.CreateLockAsync())
{
await doWorkWhileLockIsOn();
}
How do I know the work done inside the async doWorkWhileLockIsOn()
method gets done before the lock goes out of scope?
Moreover, if the CreateLockAsync()
method is awaitable, how do I know I have a lock by the time I start running doWorkWhileLockIsOn()
?
If I Wait()
on these tasks, whats the point of using async at all?
I'm sure there is something simple I'm not getting because this seems so super basic. Is there some magic state machine stuff happening in the background, because running this sort of code in the debugger is showing me this won't work well.
Thanks for any advice.
To offer a little more background I was working to make some old TransactionScope
code become async and I got runtime errors about the TransactionScope
disposing on a different thread than the one it was created on. The structure of the code is almost identical to my redlock example above which is what got me worried.
How to dispose TransactionScope in cancelable async/await?
You can see there that there is a special constructor parameter and it seems to fix things. So I'm in the "why?" stage of thinking about all of this and wondering what happens with RedLock.
Upvotes: 1
Views: 918
Reputation: 31
I need to stop posting questions when burned out and frustrated late on Friday afternoon.
I dug into the source and test code for RedlockFactory and all of the things I originally thought were not working at all appear to be working just fine, both to read the code and to use the debugger.
My real panic came from the TransactionScope problem I mentioned in my edited original question and the problems there don't seem to have anything to do with how RedlockFactory or any other items implementing DisposeAsync work.
Upvotes: 1