Function create_discarding_pub_sub

  • Creates a pub-sub where values are discarded for a subscriber if the subscriber is not actively consuming values. However, the latest value will not be discarded and will remain available for when consumption resumes.

    This is useul when a subscriber needs to continuously process latest values sequentially, but does not need to process intermediate values produced during active processing. In some sense, you can think of the newer values as being "debounced" until the subscriber has finished processing the previous value.

    Returns {
        publish: ((__namedParameters) => void);
        subscribe: (() => Object);
    }

    • publish: ((__namedParameters) => void)
        • (__namedParameters): void
        • Parameters

          • __namedParameters: Object

          Returns void

    • subscribe: (() => Object)
        • (): Object
        • Returns Object

    Example

    const { subscribe, publish } = create_discarding_pub_sub();

    (async () => {
    await timeout(500);
    publish({ value: 1 });
    await timeout(500);
    publish({ value: 2, done: true });
    })();

    for await (let value of subscribe()) {
    console.log(value);
    }

Generated using TypeDoc