A continuable represents an asynchronous operation that returns a value or an error. It also referred to as a thunk.
- "value" is any legal JavaScript value.
- "error" is a value that represents an error. It must not be falsey.
- "continuation" is a function which takes two arguments, an error and a value
- "continuable" is a function which takes a continuation as an argument
- "resolution" are the results that will be passed to a given continuation of a continuable. The resolution is either an error or a value, not both.
- "async function" is a function which does an asynchronous operation. An async function will return a continuable.
A Continuable
must be a function. It accepts a single argument:
continuable(function continuation(err, value) { })
- continuation is a required argument and it must be a function
- The continuable must produce a single resolution for this
continuation. This resolution may be synchronous or asynchronous
- If the resolution is a value then the continuation must
be called with
null
as the "error" and the value. - If the resolution is an error then the continuation must be called with the error as the "error"
- If the resolution is a value then the continuation must
be called with
- The continuable must produce a single resolution for this
continuation. This resolution may be synchronous or asynchronous
That's it. Dead simple.
continuable(function continuation(err, value) {
// the continuable has produced a resolution
if (err) {
// the continuable resoluted to an error.
} else {
// the continuable resoluted to a value.
}
})