KeyedAsyncLock
actor KeyedAsyncLock
A mutual-exclusion lock keyed by ID: callers asking for the same key wait their turn, and callers with different keys don’t affect each other.
-
Declaration
Swift
private var held: Set<UUID> -
Declaration
Swift
private var waiters: [UUID : [CheckedContinuation<Void, Never>]] -
lock(_:Asynchronous) Waits until nobody else holds
key, then holds it. Everylockmust be paired with anunlock.Declaration
Swift
func lock(_ key: UUID) async -
Releases
key, handing it straight to the longest waiter if there is one.Declaration
Swift
func unlock(_ key: UUID)
View on GitHub