mapRejected

Transforms the value of a failed task.

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(transformation)
forall e1, e2, v:
  (Task e1 v).((e1) => e2) => Task e2 v

Documentation

Transforms the value of a failed task.

Example:

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

const hello = of('hello').mapRejected(v => v.toUpperCase());
const result1 = await hello.run().promise();
$ASSERT(result1 == 'hello');

const hello2 = rejected('hello').mapRejected(v => v.toUpperCase());
try {
  const result2 = await hello2.run().promise();
  throw 'never happens';
} catch (error) {
  $ASSERT(error == 'HELLO');
}

Properties

Source Code

Defined in source/concurrency/task/_task.js at line 20, column 0
mapRejected(transformation) {
    return new Task(resolver => {
      const execution = this.run();
      resolver.onCancelled(() => execution.cancel());

      execution.listen({
        onCancelled: resolver.cancel,
        onRejected:  reason => resolver.reject(transformation(reason)),
        onResolved:  resolver.resolve
      });
    });
  }
Stability
experimental
Licence
MIT
Module
folktale/concurrency/task/_task
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)