Deferred

A deferred is an internal structure for creating Futures. Because deferred is an imperative structure, users should instead construct futures through the Task structure.

This feature is experimental!

This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.

Signature

Deferred()

Documentation

A deferred is an internal structure for creating Futures. Because deferred is an imperative structure, users should instead construct futures through the Task structure.

Static properties

Special Values

prototype

A container for methods of Deferreds.

Instance (prototype) properties

Data Fields

get _listeners

An array of visitors providing functions to be ran when the deferred's state changes.

Abstract
get _state

The current state of the deferred, as an ExecutionState.

Abstract

Debugging

inspect()

Returns a textual description of the object.

toString()

Returns a textual description of the object.

Extracting Values

future()

Retrieves the value of a deferred as a Future.

promise()

Retrieves the value of a deferred as a Promise. Cancellations are mapped to a rejected promise with a special object.

Reacting to Deferreds

listen(pattern)

Adds a visitor to be invoked when the deferred's state changes.

Resolving

cancel()

Resolves a deferred with a cancellation value.

maybeCancel()

Resolves a deferred with a cancellation value, but doesn't throw if the deferred has already been resolved.

reject(reason)

Resolves a deferred with a failure value.

resolve(value)

Resolves a deferred successfully with a value.

Source Code

Defined in source/concurrency/future/_deferred.js at line 52, column 0
function Deferred() {
  define(this, '_state', Pending());
  define(this, '_listeners', []);
}
Stability
experimental
Licence
MIT
Module
folktale/concurrency/future/_deferred
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)