Options
All
  • Public
  • Public/Protected
  • All
Menu

Queues all callers until signaled. Once signaled, all callers proceed in the order they were queued. Future callers will proceed immediately while this object remains in a signaled state.

Think of the manual reset signal as a traffic light. While it is red, all cars are queued in the order they arrive. Once the light is signaled green, the cars can proceed in the order they arrived. And as long as the light remains green, any future cars can proceed.

example
const signal = signals.manualReset();

export function bootstrap() {
// do some preliminary stuff
signal.set(); // unblock any callers
}

export async function doSomething() {
// block callers until signaled:
await signal.ready();
// bootstrap has now been called and
// completed, so we can safely perform
// an operation here
}
example
// simple pause/resume functionality

const signal = signals.manualReset(true); // start unblocked

export async function doSomething() {
await signal.ready();
// do stuff here
}

export function pause() {
signal.reset();
}

export function resume() {
signal.set();
}

Hierarchy

Index

Methods

  • ready(): Promise<void>
  • Queues the caller until the signal is placed into a signaled state.

    example
    import { tracker } from '../path/to/tracker';

    const signal = signals.manualReset(); // starts blocked

    export async function bootstrap() {
    // do bootstrap stuff here
    signal.set(); // unblock the signal
    }

    export function onReady(callback) {
    signal.ready() // block until signaled
    .then(callback)
    .catch(errors.rethrow(errors.ignore()))
    .catch(tracker.error);
    }

    Returns Promise<void>

    A Promise that will be resolved when the signal is placed into a signaled state.

  • reset(): void
  • Places the signal into a blocked (unsignaled) state. This begins queueing any future callers.

    example
    // simple pause/resume functionality

    const signal = signals.manualReset(true); // start unblocked

    export async function doSomething() {
    await signal.ready();
    // do stuff here
    }

    export function pause() {
    signal.reset();
    }

    export function resume() {
    signal.set();
    }

    Returns void

  • set(): void
  • Places the signal into a signaled state. This invokes any queued callers in the order they were queued and allows future callers to proceed immediately.

    example
    import { tracker } from '../path/to/tracker';

    const signal = signals.manualReset(); // starts blocked

    export async function bootstrap() {
    // do bootstrap stuff here
    signal.set(); // unblock the signal
    }

    export function onReady(callback) {
    signal.ready() // block until signaled
    .then(callback)
    .catch(errors.rethrow(errors.ignore()))
    .catch(tracker.error);
    }

    Returns void