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:
((Any...) => Promise v e) => (Any...) => Task e v
Converts a Promise-yielding function to a Task-yielding function.
const { fromPromised } = require('folktale/concurrency/task');
function delay(ms) {
return new Promise((resolve) => {
setTimeout(() => resolve(ms), ms)
});
}
const delayT = fromPromised(delay);
await delayT(10).run().promise();
// resolves after 10ms
fromPromised(aPromiseFn) {
return require('folktale/conversions/promised-to-task')(aPromiseFn);
}