Skip to content

Task

Task

A Task makes it easy to model asynchronous operations that may fail, such as HTTP requests or reading/writing to files/databases.

Implements: Monad, Semigroup

Task(f)

Task constructor.

Param Type Description
f function A function that takes two arguments: reject and resolve, which are functions. The function f normally initiates an asynchronous task or one that has side effects, and once it completes, it either calls the resolve function to resolve the task or rejects it.

Task.of(v)

Task constructor that creates a Task which immediately resolves.

Param Type Description
v any The value that is passed to the resolve function

Task.rejected(v)

Task constructor that creates a Task which immediately gets rejected.

Param Type Description
v any The value that is passed to the rejected function

Task.fork(reject, resolve)

Executes the Task.

Param Type Description
reject function Function to be called when the Task is rejected
resolve function Function to be called when the Task is resolved

Task.toString()

Gets a stringified version of the Task.

Task.map(f)

Applies the function f to the value of a successfully resolved Task.

Param Type Description
f function Function

Task.getValue()

Gets the function within the Task.

Task.ap(t)

Applies the successful value of the Task t to the successful value (a function) of the current Task.

Param Type Description
t Task Task with a function as the second element

Task.concat(t)

Concatenates the current Task with the passed one and returns a new Task. When resolved, it will return the successful result of both tasks.

Param Type Description
t Task Task to concatenate

Task.chain(f)

Chains together many computations that return a Task.

Param Type Description
f function Function that returns another Task

Task.toPromise()

Converts the current Task to a Promise.