Function func

  • Produces a reactive from the basis of a function. callback is executed, with its result emitted via the returned reactive.

    // Produce a random number every second
    const r = Rx.From.func(Math.random, { interval: 1000 });

    callback can be called repeatedly by providing the interval option to set the rate of repeat. Looping can be limited with options.maximumRepeats, or passing a signal options.signal and then activating it.

    // Reactive that emits a random number every second, five times
    const r1 = Rx.From.func(Math.random, { interval: 1000, maximumRepeats: 5 }
    // Generate a random number every second until ac.abort() is called
    const ac = new AbortController();
    const r2 = Rx.From.func(Math.random, { interval: 1000, signal: ac.signal });

    The third option is for callback to fire the provided abort function.

    Rx.From.func((abort) => {
    if (Math.random() > 0.5) abort('Random exit');
    return 1;
    });

    By default has a laziness of 'very' meaning that callback is run only when there's a subscriber By default stream closes if callback throws an error. Use options.closeOnError:'ignore' to change.

    Type Parameters

    • V

    Parameters

    Returns ReactivePingable<V>