Converts a function with a Node-style callback to 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 s, e, r:
((Any..., (e, s) => Void) => Void)
=> (Any...)
=> Task e s r
Converts a function with a Node-style callback to a Task
.
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');
fn => (...args) => (
task(r =>
fn(...args, (err, data) => err ? r.reject(err) : r.resolve(data))
)
)