import { Notify } from "https://deno.land/x/async@v2.0.2/mod.ts";
Async notifier that allows one or more "waiters" to wait for a notification.
import { assertEquals } from "https://deno.land/std@0.186.0/testing/asserts.ts";
import { promiseState } from "./state.ts";
import { Notify } from "./notify.ts";
const notify = new Notify();
const waiter1 = notify.notified();
const waiter2 = notify.notified();
notify.notify();
assertEquals(await promiseState(waiter1), "fulfilled");
assertEquals(await promiseState(waiter2), "pending");
notify.notify();
assertEquals(await promiseState(waiter1), "fulfilled");
assertEquals(await promiseState(waiter2), "fulfilled");
Methods
notified(unnamed 0?: WaitOptions): Promise<void>
Asynchronously waits for notification. The caller's execution is suspended until
the notify
method is called. The method returns a Promise that resolves when the caller is notified.
Optionally takes an AbortSignal to abort the waiting if the signal is aborted.
notify(n?): void
Notifies n
waiters that are waiting for notification. Resolves each of the notified waiters.
If there are fewer than n
waiters, all waiters are notified.
notifyAll(): void
Notifies all waiters that are waiting for notification. Resolves each of the notified waiters.