toPromise

Converts a Future into a Promise.

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

value()
forall e, v:
  (Future e v).() => Promise v e

Documentation

Converts a Future into a Promise.

Note that this conversion may not be as accurate due to the differences in Promise and Future semantics. In particular, Promises recursively flatten any object with a .then method, and do not have a separate representation for cancellations.

Cancelled futures are converted to rejected promises with a special Cancelled() object.

Example:

const Future = require('folktale/concurrency/future');

$ASSERT(
  (await Future.of(1).toPromise()) == 1
);

try {
  await Future.rejected(1).toPromise();
  throw 'never happens';
} catch (e) {
  $ASSERT(e == 1)
}

Properties

Source Code

Defined in source/concurrency/future/_future.js at line 24, column 0
toPromise() {
    return require('folktale/conversions/future-to-promise')(this);
  }
Stability
experimental
Licence
MIT
Module
folktale/concurrency/future/_future
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)