promisedToTask

Converts a Promise-yielding function to a Task-yielding function.

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

promisedToTask(aPromiseFn)
forall e, v, r:
  ((Any...) => Promise v e) => (Any...) => Task e v r

Documentation

Converts a Promise-yielding function to a Task-yielding function.

Example:

const promisedToTask = require('folktale/conversions/promised-to-task');

function delay(ms) {
  return new Promise((resolve) => {
    setTimeout(() => resolve(ms), ms)
  });
}

const delayT = promisedToTask(delay);

await delayT(10).run().promise();
// resolves after 10ms

Properties

Source Code

Defined in source/conversions/promised-to-task.js at line 19, column 0
(aPromiseFn) => {
  return (...args) => task(resolver => {
    aPromiseFn(...args).then(
      (value) => resolver.resolve(value),
      (error) => resolver.reject(error)
    );
  });
}
Stability
experimental
Licence
MIT
Module
folktale/conversions/promised-to-task
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)