Creates a new Signal instance.
If true, the signal will automatically reset after releasing a waiter. If false, the signal will remain signaled until manually reset.
The initial state of the signal. Default is false (non-signaled).
Indicates whether the signal is in the signaled state.
Reset the signal to non-signaled state
Set the signal to signaled state
Notifies waiting listeners. If autoReset is true, only one listener
will be notified and the signal will reset to non-signaled state.
If autoReset is false, all listeners will be notified.
Listeners are notified asynchronously.
Wait for the signal to be signaled.
If the signal is already signaled, the listener is called immediately.
If autoReset is true, the signal is reset to non-signaled state after
notifying a listener.
Note: If multiple listeners are waiting and the signal is signaled, only one
listener will be notified if autoReset is true. If autoReset is false,
all listeners will be notified.
Optionalsignal: AbortSignal | nullAn AbortSignal that can be used to cancel the wait operation.
A promise that resolves when the signal is signaled, or rejects when aborted.
A signal primitive for signaling between async tasks.
When the signal is in the signaled state, calls to
waitwill resolve immediately. When the signal is in the non-signaled state, calls towaitwill block until the signal is signaled. Waiters are released in FIFO order.The signal can be configured to auto-reset or manual-reset.
If
autoResetis true, the signal will automatically reset to the non-signaled state after a single waiter is released, acting like a binary semaphore. IfautoResetis false, the signal will remain in the signaled state until it is manually reset.Example
Example