Table of Contents

Interface ISafetyService

Namespace
NArk.Abstractions.Safety
Assembly
NArk.Abstractions.dll

Provides distributed locking to prevent concurrent operations on the same resources (e.g., double-spending the same VTXO, concurrent batch signing for the same wallet).

public interface ISafetyService

Methods

LockKeyAsync(string, CancellationToken)

Acquires an exclusive lock on a single key. Dispose the result to release.

Task<CompositeDisposable> LockKeyAsync(string key, CancellationToken ct)

Parameters

key string
ct CancellationToken

Returns

Task<CompositeDisposable>

LockKeysAsync(ImmutableSortedSet<string>, CancellationToken)

Acquires exclusive locks on multiple keys atomically (sorted to prevent deadlocks). Dispose the result to release all locks.

Task<CompositeDisposable> LockKeysAsync(ImmutableSortedSet<string> keys, CancellationToken ct)

Parameters

keys ImmutableSortedSet<string>
ct CancellationToken

Returns

Task<CompositeDisposable>

TryLockByTimeAsync(string, TimeSpan)

Attempts to acquire a time-limited lock. Returns true if acquired, false if already held.

Task<bool> TryLockByTimeAsync(string key, TimeSpan timeSpan)

Parameters

key string
timeSpan TimeSpan

Returns

Task<bool>