Condition

Condition

A classic multitasking Condition mechanism.

Constructor

new Condition(lockopt)

Source:
See:
Example
const cond = new Condition();
await cond.acquire();
setTimeout(() => cond.notify(), 1000);
await cond.wait(); // will wait for 1000ms
// do work...
cond.release();
Parameters:
Name Type Attributes Description
lock Lock <optional>
A shared lock object that is used to synchronize multiple Conditions.

Classes

Condition

Methods

(async) acquire()

Source:
See:
Acquire the internal lock.

locked() → {boolean}

Source:
See:
The internal lock state.
Returns:
Type
boolean

notify(nopt)

Source:
Wake up any awaiters using wait.
Parameters:
Name Type Attributes Default Description
n Number <optional>
1 The number of awaiters to wake up.

notifyAll()

Source:
Wake up ALL awaiters using wait.

release()

Source:
See:
Release the internal lock.

(async) wait()

Source:
Wait until the condition is satisfied. When multiple awaiters exist they will be woken up one at a time if notify is used. If notifyAll is used then all awaiters will be woken up. Once completed the internal Lock is reacquired.