map

Transforms the value of a successful 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 e, v1, v2:
  (Task e v1).((v1) => v2) => Task e v2

Documentation

Transforms the value of a successful task.

Example:

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

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

const hello2 = rejected('hello').map(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
map(transformation) {
    return new Task(resolver => {
      const execution = this.run();
      resolver.onCancelled(() => execution.cancel());

      execution.listen({
        onCancelled: resolver.cancel,
        onRejected:  resolver.reject,
        onResolved:  value => resolver.resolve(transformation(value))
      });
    });
  }
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/)