Add foundation

This commit is contained in:
TheXamlGuy
2024-04-13 11:29:32 +01:00
parent 6f31aa8513
commit 053d8a851e
264 changed files with 3428 additions and 4683 deletions
+23
View File
@@ -0,0 +1,23 @@
using System.Runtime.CompilerServices;
namespace Toolkit.Foundation;
public class AsyncLock(int initial = 1,
int maximum = 1) :
IDisposable
{
private readonly SemaphoreSlim semaphore = new(initial, maximum);
public void Dispose()
{
semaphore.Release();
}
public TaskAwaiter<AsyncLock> GetAwaiter() => LockAsync().GetAwaiter();
private async Task<AsyncLock> LockAsync()
{
await semaphore.WaitAsync();
return this;
}
}