Allows using a direct style of programming (similar to async/await
for Promises) to sequence Tasks. The function must return a Task.
This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
forall v, e: (Generator [Task e v Any]) => Task e [v] Any
Allows using a direct style of programming (similar to async/await
for Promises) to sequence Tasks. The function must return a Task.
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);
(generatorFn) =>
new Task((resolver) => resolver.resolve(generatorFn()))
.chain((generator) => nextGeneratorValue(generator)())