tumtumtum / Shaolinq

ORM for .NET with full LINQ support for Postgres, Sqlite, MySql and SqlServer
Other
127 stars 19 forks source link

AsyncRewriter generates invalid code within a lock #76

Open samcook opened 7 years ago

samcook commented 7 years ago

AsyncRewriter inserts async method calls inside code that is within a lock section, however this won't compile (Cannot await in the body of a lock statement):

lock (lockObj)
{
    // can't do this inside a lock
    await this.MethodAsync(cancellationToken).ConfigureAwait(false);
}

Can be worked around by using something like SemaphoreSlim instead:

await semaphoreSlim.WaitAsync();
try
{
    // synchronised code here
}
finally
{
    semaphoreSlim.Release();
}