The number of active retains
Acquire a drain.
Prevents new retains immediately and waits for all existing retain handles to be disposed. The retainer remains drained until the returned handle is disposed.
Optionalsignal: AbortSignalan optional abort signal to abort the drain acquisition
Try to retain the resource.
Returns undefined if a drain is active or pending.
If errorWhenDraining is provided, throws that error instead.
When a function is provided, its result will be thrown
(this is an optimization to avoid constructing an Error object when it's not being thrown).
Try to retain the resource.
Returns undefined if a drain is active or pending.
If errorWhenDraining is provided, throws that error instead.
When a function is provided, its result will be thrown
(this is an optimization to avoid constructing an Error object when it's not being thrown).
A utility for retaining a resource while it's being used, and for draining it by blocking new retain requests and waiting for existing retains to be released.
tryRetainacquires a retain handle if no drain is active or pending.acquireDrainprevents new retain handles from being acquired, waits for existing retain handles to be released, and resolves with a drain handle that keeps the retainer drained until disposed.Multiple drain handles can be held in parallel. New retain handles are allowed again when the last drain handle is disposed.
Example