Function race

  • Given an array of tasks, produce a new Task which will resolve or reject with the resolution or rejection of the first task which settles.

    import Task, { race } from 'true-myth/task';

    let { task: task1, resolve } = Task.withResolvers();
    let task2 = new Task((_resolve) => {});
    let task3 = new Task((_resolve) => {});

    resolve("Cool!");
    let theResult = await race([task1, task2, task3]);
    console.log(theResult.toString()); // Ok("Cool!")

    Parameters

    • tasks: []

      The tasks to race against each other.

    Returns Task<never, never>

  • Given an array of tasks, produce a new Task which will resolve or reject with the resolution or rejection of the first task which settles.

    import Task, { race } from 'true-myth/task';

    let { task: task1, resolve } = Task.withResolvers();
    let task2 = new Task((_resolve) => {});
    let task3 = new Task((_resolve) => {});

    resolve("Cool!");
    let theResult = await race([task1, task2, task3]);
    console.log(theResult.toString()); // Ok("Cool!")

    Type Parameters

    • A extends readonly AnyTask[]

      The type of the array or tuple of tasks.

    Parameters

    • tasks: A

      The tasks to race against each other.

    Returns Task<TaskTypesFor<A>[0][number], TaskTypesFor<A>[1][number]>