Last active
October 9, 2016 13:46
-
-
Save craigdallimore/78fd15bd0372d6b4294d585f923c4700 to your computer and use it in GitHub Desktop.
Parallel future example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mkFuture = v => Future((reject, resolve) => { | |
console.log(`start: ${v}`); | |
setTimeout(() => { | |
console.log(`resolve: ${v}`) | |
resolve(v); | |
}, Math.random() * 1000); | |
}); | |
let futures = [1,2,3,4].map(mkFuture); | |
let safeErr = x => console.error(x); | |
let safeLog = x => console.log(x); | |
// Start in order, resolve in any order, emit array in order. | |
sequence(Future.of, futures).fork(safeErr, safeLog) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment