Interface Task<R>

Task monad interface

interface Task<R> {
    cancel: (() => void);
    generator: TaskGeneratorFunction<[], unknown, Task<R>, R>;
    reject: ((error) => void);
    resolve: (() => TaskInvoke<R>);
    chain<R2>(op): Task<R2>;
    chainCanceled<R2>(op): Task<R | R2>;
    chainRejected<R2>(op): Task<R | R2>;
    map<R2>(op): Task<R2>;
    mapCanceled<R2>(op): Task<R | R2>;
    mapRejected<R2>(op): Task<R | R2>;
    matchChain<R2, R3, R4>(op): Task<R2 | R3 | R4>;
    matchMap<R2, R3, R4>(op): Task<R2 | R3 | R4>;
    matchTap(op): Task<R>;
    tap(op): Task<R>;
    tapCanceled(op): Task<R>;
    tapRejected(op): Task<R>;
}

Type Parameters

  • R

    task resolve type

Hierarchy

  • TaskBase<R>
    • Task

Properties

cancel: (() => void)

Invoke underlying canel method without error

Type declaration

    • (): void
    • Invoke underlying canel method without error

      Returns void

generator: TaskGeneratorFunction<[], unknown, Task<R>, R>

Wrap task to singleton generator

Userful in order to avoid ambiguous yied types

Returns

generator of task wrapping the task

Example

const getString = () => Task.resolved('hello');
const getLength = (data: string) => Task.resolved(data.length);

// ..... //

Task.generate(function* () {
const data = yield getString(); // data: string | number
const length = yield getLength(data); // length: string | number

return length;
});

// ..... //

Task.generate(function* () {
const data = yield* getString().generator(); // data: string
const length = yield* getLength(data).generator(); // length: number

return length;
});
reject: ((error) => void)

Invoke underlying canel method with error

Type declaration

    • (error): void
    • Invoke underlying canel method with error

      Parameters

      • error: any

        error value to be injected from outside

      Returns void

Param: error

error value to be injected from outside

resolve: (() => TaskInvoke<R>)

Return underlying promise in order to await result

Type declaration

    • (): TaskInvoke<R>
    • Return underlying promise in order to await result

      Returns TaskInvoke<R>

      underlying promise

Returns

underlying promise

Methods

  • Invoke transformer when task is resolved (and only then) and continue execution with it's result

    Type Parameters

    • R2

      transformer task resolve type

    Parameters

    • op: ((value) => Task<R2>)

      transformer to invoke

    Returns Task<R2>

    task chaining to transformer result task

  • Invoke transformer when task is canceled (and only then) and continue execution with it's result

    Type Parameters

    • R2

      fallback task resolve type

    Parameters

    Returns Task<R | R2>

    task chaining to fallback task in case of cancelation

  • Invoke transformer when task is rejected (and only then) and continue execution with it's result

    Type Parameters

    • R2

      fallback task resolve type

    Parameters

    • op: ((error) => Task<R2>)

      transformer to invoke

    Returns Task<R | R2>

    task chaining to fallback task in case of failure

  • Invoke transformer when task is resolved (and only then) and return it's result instead

    Type Parameters

    • R2

      transformer return type

    Parameters

    • op: ((value) => R2)

      transformer to invoke

        • (value): R2
        • Parameters

          • value: R

          Returns R2

    Returns Task<R2>

    task returning transformer result

  • Invoke transformer when task is canceled (and only then) and return it's result instead

    Type Parameters

    • R2

      fallback return type

    Parameters

    • op: (() => R2)

      transformer to invoke

    Returns Task<R | R2>

    task returning fallback result in case of cancelation

  • Invoke transformer when task is rejected (and only then) and return it's result instead

    Type Parameters

    • R2

      fallback return type

    Parameters

    • op: ((error) => R2)

      transformer to invoke

        • (error): R2
        • Parameters

          • error: any

          Returns R2

    Returns Task<R | R2>

    task returning fallback result in case of failure

  • Invoke a dedicated transformer according to task resolution and continue execution with it's result

    Type Parameters

    • R2

      success transformer resolve type

    • R3 = R2

      failure transformer resolve type

    • R4 = R3

      cancelation transformer resolve type

    Parameters

    • op: {
          canceled: (() => Task<R4>);
          rejected: ((error) => Task<R3>);
          resolved: ((value) => Task<R2>);
      }
      • canceled: (() => Task<R4>)

        transformer to invoke on cancelation

          • (): Task<R4>
          • transformer to invoke on cancelation

            Returns Task<R4>

      • rejected: ((error) => Task<R3>)

        transformer to invoke on failure

          • (error): Task<R3>
          • transformer to invoke on failure

            Parameters

            • error: any

            Returns Task<R3>

      • resolved: ((value) => Task<R2>)

        transformer to invoke on success

          • (value): Task<R2>
          • transformer to invoke on success

            Parameters

            • value: R

            Returns Task<R2>

    Returns Task<R2 | R3 | R4>

    task chaining to a corresponding transformer result

  • Invoke a dedicated transformer according to task resolution

    Type Parameters

    • R2

      success transformer return type

    • R3 = R2

      failure transformer return type

    • R4 = R3

      cancelation transformer return type

    Parameters

    • op: {
          canceled: (() => R4);
          rejected: ((error) => R3);
          resolved: ((value) => R2);
      }
      • canceled: (() => R4)

        transformer to invoke on cancelation

          • (): R4
          • transformer to invoke on cancelation

            Returns R4

      • rejected: ((error) => R3)

        transformer to invoke on failure

          • (error): R3
          • transformer to invoke on failure

            Parameters

            • error: any

            Returns R3

      • resolved: ((value) => R2)

        transformer to invoke on success

          • (value): R2
          • transformer to invoke on success

            Parameters

            • value: R

            Returns R2

    Returns Task<R2 | R3 | R4>

    task resolving to a corresponding transformer result

  • Invoke a dedicated callback according to task resolution

    Parameters

    • op: {
          canceled: (() => void);
          rejected: ((error) => void);
          resolved: ((value) => void);
      }
      • canceled: (() => void)

        callback to invoke on cancelation

          • (): void
          • callback to invoke on cancelation

            Returns void

      • rejected: ((error) => void)

        callback to invoke on failure

          • (error): void
          • callback to invoke on failure

            Parameters

            • error: any

            Returns void

      • resolved: ((value) => void)

        callback to invoke on success

          • (value): void
          • callback to invoke on success

            Parameters

            • value: R

            Returns void

    Returns Task<R>

    self

  • Invoke callback when task is resolved (and only then)

    Parameters

    • op: ((value) => void)

      callback to invoke

        • (value): void
        • Parameters

          • value: R

          Returns void

    Returns Task<R>

    self

  • Invoke callback when task is canceled (and only then)

    Parameters

    • op: (() => void)

      callback to invoke

        • (): void
        • Returns void

    Returns Task<R>

    self

  • Invoke callback when task is rejected (and only then)

    Parameters

    • op: ((error) => void)

      callback to invoke

        • (error): void
        • Parameters

          • error: any

          Returns void

    Returns Task<R>

    self

Generated using TypeDoc