nodebackToTask

Converts a function with a Node-style callback to 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

nodebackToTask(fn)
forall s, e, r:
((Any..., (e, s) => Void) => Void)
=> (Any...)
=> Task e s r

Documentation

Converts a function with a Node-style callback to a Task.

Example:

const nodebackFromTask = require('folktale/conversions/nodeback-to-task');

const fn = (str, str2, cb) => cb(null, str + str2 + 'processed');
const convertedFn = nodebackFromTask(fn);
const task = convertedFn('test', '-was-');
const value = await task.run().promise();

$ASSERT(value === 'test-was-processed');

Properties

Source Code

Defined in source/conversions/nodeback-to-task.js at line 23, column 0
fn => (...args) => (
  task(r =>
    fn(...args, (err, data) => err ? r.reject(err) : r.resolve(data))
  )
)
Stability
experimental
Licence
MIT
Module
folktale/conversions/nodeback-to-task
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • @rpearce
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)