BrighterCommand / Brighter

A framework for building messaging apps with .NET and C#.
https://www.goparamore.io/
MIT License
2k stars 256 forks source link

[Feature] Only support `async` methods in `IDistributedLock` #3110

Open dhickie opened 3 months ago

dhickie commented 3 months ago

Is your feature request related to a problem? Please describe. When implementing a DynamoDb implementation of IDistributedLock, I came across the issue that the .NET SDK for Dynamo DB doesn't support synchronous methods. As a result, when implementing ObtainLock, there's a risk of deadlock when doing the following:

public bool ObtainLock(string resource)
{
    return ObtainLockAsync(resource, CancellationToken.None).GetAwaiter().GetResult();
}

Describe the solution you'd like Drop the synchronous methods from the interface. Implementations that don't have async methods can use Task.FromResult as a workaround. This would, however, also mean that the lambda passed to the Timer instance in TimedOutboxSweeper would also need to be async.

Additional context Builds on the recent distributed lock work by @preardon.

iancooper commented 3 months ago

@preardon Can you take a look at this?

preardon commented 2 months ago

@iancooper I'm happy to drop sync flows if you are. let me know and I'll get on it

iancooper commented 2 months ago

Do it

preardon commented 1 month ago

This has now been merged in for both v9 and v10 and will come out with the next release

3202 #3203