Inverts the state of a Future: successes become failures, failures become successes.
This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
Inverts the state of a Future: successes become failures, failures become successes.
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)
});
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();
}