control.async¶| Stability: | 1 - Experimental |
|---|---|
| Bug Tracker: | https://github.com/folktale/control.async |
| Version: | 0.5.1 |
| Repository: | https://github.com/folktale/control.async |
| Portability: | Portable |
| npm package: | control.async |
Task(_, _) → AsyncModule
Operations for asynchronous control flow.
Require the control.async package, after installing it, and give it a
valid data.task.Task object to instantiate it:
1 2 | var Task = require('data.task')
var Async = require('control.async')(Task)
|
control.async.parallel(tasks)¶| Returns: | A task that runs the given ones in parallel. |
|---|
Array(Task(α, β)) → Task(α, Array(β))
Resolves all tasks in parallel, and collects their results.
control.async.nondeterministicChoice(tasks)¶| Returns: | A task that selects the first task to resolve. |
|---|
Array(Task(α, β)) → Task(α, Maybe(β))
Runs all tasks in parallel, selects the first one to either succeed or fail.
control.async.lift(function)¶(α₁, α₂, ..., αₙ, (β → Unit)) → (α₁, α₂, ..., αₙ → Task(Unit, β))
Converts a function that takes a simple continuation to a Task.
control.async.liftNode(function)¶(α₁, α₂, ..., αₙ, (β, γ → Unit)) → (α₁, α₂, ..., αₙ → Task(β, γ))
Converts a function that takes a Node-style continuation to a Task.
control.async.toNode(task)¶Task(α, β) → (α | null, β | null → Unit)
Converts a Task to a Node-style function.
control.async.fromPromise(promise)¶Promise(α, β) → Task(α, β)
Converts a Promises/A+ to a Task.
control.async.toPromise(constructor, task)¶PromiseConstructor → Task(α, β) → Promise(α, β)
type PromiseConstructor = new((α → Unit), (β → Unit) → Unit)
→ Promise(α, β)
Converts from Task to Promises/A+.
Note
Do note that nested Tasks, unlike Promises/A+, are NOT
flattened. You need to manually call control.monads.join()
until you get to the value itself, if you care about passing
just the value.
control.async.delay(milliseconds)¶| Returns: | A Task that succeeds after N milliseconds. |
|---|
Number → Task(Unit, Number)
Constructs a Task that always succeeds after at least N milliseconds. The value of the Task will be the delta from the time of its initial execution to the time it gets resolved.