Skip to content

Instantly share code, notes, and snippets.

@craigdallimore
Created October 9, 2016 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigdallimore/531245130c1b129616356d6fcf6d42d5 to your computer and use it in GitHub Desktop.
Save craigdallimore/531245130c1b129616356d6fcf6d42d5 to your computer and use it in GitHub Desktop.
Series future example
// mkFuture
// :: Any next
// -> Any prev
// -> Future next
let mkFuture = next => prev => Future((reject, resolve) => {
console.log(`start: ${prev},${next}`);
setTimeout(() => {
console.log(`resolve: ${prev},${next}`)
resolve(next);
}, Math.random() * 1000);
});
let safeErr = x => console.error(`err : ${x}`);
let safeLog = x => console.log(`log : ${x}`);
// toSeries
// :: Future f, Any v
// -> Future
const toSeries = (f, v) => f.chain(mkFuture(v));
// series :: Future
const series = reduce(toSeries, Future.of(0), [1,2,3,4]);
series.fork(safeErr, safeLog);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment