# future

> The promise / subscribe / deferred module of FuturesJS (Ender.JS and Node.JS)

Latest version **2.3.1** (published 2012-05-31) · 0 weekly downloads

## Install

```sh
npm install future
pnpm add future
yarn add future
bun add future
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.1 |
| Published | 2012-05-31 |
| First published | 2011-07-13 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | AJ ONeal |
| Maintainers | coolaj86 |
| Keywords | flow-control, async, asynchronous, futures, promises, deferreds, util, browser |

## Links

- npm: https://www.npmjs.com/package/future
- Repository: https://github.com/coolaj86/futures
- npm.io page: https://npm.io/package/future

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 2.3.1 (latest) — 2012-05-31
- 2.2.0 — 2012-01-22
- 2.1.1 — 2011-07-13

## README

Future
----

Creates a Future (aka Promise, Deferred, Subscription, Callback) object.

Installation
---

Node.JS (Server):

    npm install future

Ender.JS (Browser):

    ender build future

Usage
---

    var context = { "foo": "bar" }
      , Future = require('future')
      , future = Future.create(context)
      , err
      , message = "Hello World!"
      ;

    future.whenever(function (error, data) {
      if (error) {
        throw err;
      }
      console.log(this.foo + " says: " + data);
    });

    future.setTimeout(100);
    future.deliver(err, message);

Output:

    "bar says: Hello World"
    FutureTimeout: timeout 100ms
        at [object SomeObject]:x:y
        ...

API
---

Creates a Future (aka Promise, Deferred, Subscription, Callback) object.

**Core**

  * `Futures.future(globalContext=null)` - creates a `Future` object and uses `globalContext` as the default `this` for callbacks

  * `deliver(err, data, ...)` - Send a message (data) to all listeners (callbacks)

  * `fulfill([err, data, ...])` - Prevent the sending of any future messages. If arguments are passed they will be `deliver`ed.

  * `whenever(callback, [context])` - Listen to all messages, applying `context` if provided (passing `null` cancels `globalContext`)

  * `when(callback, [context])` - Listen one-time only, then `removeCallback` automatically

  * `setTimeout(ms)` - will sends a `FutureTimeout` error if no activity occurs within `ms`


**Accessory**

  * `errback(err)` - Useful for a peer-library requiring a method specifically for errbacks
    * i.e. `jQuery`'s `$.ajax`

  * `callback(data [, ...])` - Useful for a peer-library requiring a method which does not pass `err` as the first parameter
    * i.e. `jQuery`'s `$.ajax`

  * `removeCallback(callback, context=null)` - This callback and associated context will no longer receive messages

  * `setAsap(on=true)` - New listeners get existing data (if available) rather than waiting until the next delivery (default on)

  * `isFuture(obj)` - a best-effort guess as to whether or not an object is a Future

  * `callbackCount(callback, context)` - The number of listening callbacks

  * `deliveryCount(callback, context)` - The number of deliveries made

  * `hasCallback(callback, context=null)` - Returns `true` if the callback is listening


Example
---

    var context = { "foo": "bar" },
      future = Futures.future(context),
      err,
      message = "Hello World!";

    future.whenever(function (error, data) {
      if (error) {
        throw err;
      }
      console.log(this.foo + " says: " + data);
    });

    future.setTimeout(100);
    future.deliver(err, message);

Output:

    "bar says: Hello World"
    FutureTimeout: timeout 100ms
        at [object SomeObject]:x:y
        ...

---
_Source: https://npm.io/package/future · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
