Skip to content

A simple, but reliable distributed lock which does not require a dedicated server

License

Notifications You must be signed in to change notification settings

osavoskin/globallock

Repository files navigation

Global Lock

A simple, but reliable distributed lock which does not require a dedicated server

Installation

dotnet add package SynchronizationUtils.GlobalLock

Usage

// Register the service with the IoC container
servises.AddGlobalLock(storageConnectionString);

using var globalLock = serviceProvider.GetRequiredService<IGlobalLock>();
await using var lease = await globalLock.TryAcquire(resource, scope);

if (lease.IsAcquired)
{
    // Got exclusive access to the resource across all nodes/processes
    // Do something with it..
}
else
{
    // Hm, that's unfortunate - the resource is being owned by another process
    // Let's wait while it is available..

    await lease.Wait();

    // Got it, it is safe to proceed now..
}

About

A simple, but reliable distributed lock which does not require a dedicated server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages