Converts a Promise-yielding function to a Task-yielding function.
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 e, v, r:
((Any...) => Promise v e) => (Any...) => Task e v r
Converts a Promise-yielding function to a Task-yielding function.
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
(aPromiseFn) => {
return (...args) => task(resolver => {
aPromiseFn(...args).then(
(value) => resolver.resolve(value),
(error) => resolver.reject(error)
);
});
}