Function all

  • Given an array of tasks, return a new Task which resolves once all tasks successfully resolve or any task rejects.

    Once all tasks resolve:

    import { all, timer } from 'true-myth/task';

    let allTasks = all([
    timer(10),
    timer(100),
    timer(1_000),
    ]);

    let result = await allTasks;
    console.log(result.toString()); // [Ok(10,100,1000)]

    If any tasks do not resolve:

    let { task: willReject, reject } = Task.withResolvers<never, string>();

    let allTasks = all([
    timer(10),
    timer(20),
    willReject,
    ]);

    reject("something went wrong");
    let result = await allTasks;
    console.log(result.toString()); // Err("something went wrong")

    Parameters

    • tasks: []

      The list of tasks to wait on.

    Returns Task<[], never>

  • Given an array of tasks, return a new Task which resolves once all tasks successfully resolve or any task rejects.

    Once all tasks resolve:

    import { all, timer } from 'true-myth/task';

    let allTasks = all([
    timer(10),
    timer(100),
    timer(1_000),
    ]);

    let result = await allTasks;
    console.log(result.toString()); // [Ok(10,100,1000)]

    If any tasks do not resolve:

    let { task: willReject, reject } = Task.withResolvers<never, string>();

    let allTasks = all([
    timer(10),
    timer(20),
    willReject,
    ]);

    reject("something went wrong");
    let result = await allTasks;
    console.log(result.toString()); // Err("something went wrong")

    Type Parameters

    • A extends readonly AnyTask[]

      The type of the array or tuple of tasks.

    Parameters

    • tasks: A

      The list of tasks to wait on.

    Returns All<A>