taskDo

Allows using a direct style of programming (similar to async/await for Promises) to sequence Tasks. The function must return a 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

taskDo(generatorFn)
forall v, e: (Generator [Task e v Any]) => Task e [v] Any

Documentation

Allows using a direct style of programming (similar to async/await for Promises) to sequence Tasks. The function must return a Task.

Example:

const task = require('folktale/concurrency/task');

const resultTask = task.do(function* () {
  const a = yield task.of(1);
  const b = yield task.of(2);

  return task.of((a + b) * (yield task.of(3)));
});

const value = await resultTask.run().promise();
$ASSERT(value == 9);

Properties

Source Code

Defined in source/concurrency/task/do.js at line 28, column 0
(generatorFn) => 
  new Task((resolver) => resolver.resolve(generatorFn()))
    .chain((generator) => nextGeneratorValue(generator)())
Stability
experimental
Licence
MIT
Module
folktale/concurrency/task/do
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)