Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Callable

  • SequentialFunction(...args: any[]): Promise<any>
  • async
    example
    // as a standalone function

    const process = functions.sequence();

    async function handler1(...args, lastHandlerResult) {
    console.log(args, lastHandlerResult);
    await someAsyncMethod(...args);
    return 1;
    }

    function handler2(...args, lastHandlerResult) {
    console.log(args, lastHandlerResult);
    return 2;
    }

    process.add(handler1);
    process.add(handler2);

    await process('abc', 'def'); // 2
    // output from handler1: ['abc', 'def'], undefined
    // output from handler2: ['abc', 'def'], 1
    example
    // as a combination event handler

    function handler1(...args) {
    return 'some value';
    }

    function handler2(...args, previousValue) {
    return previousValue === 'some value';
    }

    const bus = events.bus();

    bus.on('event', functions.sequence(handler1, handler2));
    await bus.fire('event', 'arg1', 'arg2'); // [true]

    Parameters

    • Rest ...args: any[]

      The arguments to pass to the original functions.

    Returns Promise<any>

    A Promise resolved with the last function's settled return value, or rejected if any function rejects or throws an error. The functions will be passed the incoming arguments along with the value returned by the previous function.

Index

Methods

  • Adds one or more functions to the underlying Set and returns the original grouped function for chaining.

    Parameters

    • Rest ...fns: Function[]

      One or more functions to add to the underlying collection.

    Returns SequentialFunction

    The original grouped function instance.

  • Creates and returns a new copy of the grouped function. Methods can be added or removed from this function without modifying the original.

    Returns SequentialFunction

    A new copy of the original grouped function that can be modified without affecting the original.

  • Adds one or more functions to the underlying Set, starting at the given index, and returns the original grouped function for chaining.

    Parameters

    • index: number

      The position at which to begin inserting functions.

    • Rest ...fns: Function[]

      One or more functions to insert into the underlying Set.

    Returns SequentialFunction

    The original grouped function instance.

  • Removes one or more functions from the underlying Set and returns the original grouped function for chaining.

    Parameters

    • Rest ...fns: Function[]

      One or more functions to remove from the underlying Set.

    Returns SequentialFunction

    The original grouped function instance.