swap

Inverts the state of a Future: successes become failures, failures become successes.

Signature

value()
(Future 'f 's).() => Future 's 'f

Documentation

Inverts the state of a Future: successes become failures, failures become successes.

Example:

const { of, rejected } = require('folktale/concurrency/future');

of(1).swap().listen({
  onRejected: (x) => $ASSERT(x == 1)
});

rejected(1).swap().listen({
  onResolved: (x) => $ASSERT(x == 1)
});

Properties

Source Code

Defined in source/concurrency/future/_future.js at line 24, column 0
swap() {
    let deferred = new Deferred();    // eslint-disable-line prefer-const
    this.listen({
      onCancelled: ()     => deferred.cancel(),
      onRejected:  reason => deferred.resolve(reason),
      onResolved:  value  => deferred.reject(value) 
    });

    return deferred.future();
  }
Stability
stable
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/)