import { Condition } from "https://deno.land/x/async@v1.1.5/mod.ts";
A Condition object. Not thread-safe.
A condition primitive can be used by a task to wait for some event to happen and then get exclusive access to a shared resource.
In essence, a Condition object combines the functionality of an Event and Lock. It is possible to have multiple Condition objects share one Lock, which allows coordinating exclusive access to a shared resource between different tasks interested in particular states of that shared resource.
The optional lock argument must be a Lock object or undefined. In the latter case a new Lock object is created automatically.
The preferred way to use a Condition is with()
method.
Constructors
Methods
Acquire the underlying lock.
This method waits until the underlying lock is unlocked, sets it to locked and returns true.
Return true
if the underlying lock is acquired.
Wake up at most n tasks (1 by default) waiting on this condition. The method is no-op if no tasks are waiting.
The lock must be acquired before this method is called and released shortly after. If called with an unlocked lock an Error is thrown.
Wake up all tasks waiting on this condition.
This method acts like notify()
, but wakes up all waiting tasks.
The lock must be acquired before this method is called and released shortly after. If called with an unlocked lock an Error is thrown.
Release the underlying lock.
When invoked on an unlocked lock, an Error is thrown.
Wait until notified.
If the calling task has not acquired the lock when this method is called, an Error is thrown.
This method release the underlying lock, and the blocks until it is awakened
by a notify()
or notify_all()
call. Once awakened, the Condition re-acquires
itsock and this method returns true
.
Wait until a predicate becomes true.
The predicate must be a callable which result is a boolean value.
Acuire the lock and execute callback to access shared state.
This is preferred way to use a Condition.