Task
Task
A Task makes it easy to model asynchronous operations that may fail, such as HTTP requests or reading/writing to files/databases.
Task(f)
Task constructor.
| Param | Type | Description | 
|---|---|---|
| f | function | A function that takes two arguments: rejectandresolve, which are functions. The functionfnormally initiates an asynchronous task or one that has side effects, and once it completes, it either calls theresolvefunction 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 resolvefunction | 
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 rejectedfunction | 
Task.fork(reject, resolve)
Executes the Task.
| Param | Type | Description | 
|---|---|---|
| reject | function | Function to be called when the Taskis rejected | 
| resolve | function | Function to be called when the Taskis 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 | Taskwith 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 | Taskto 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.