Created
March 3, 2017 18:41
-
-
Save ataube/f2fcf05fccedc5bb52319f12815e6d0d to your computer and use it in GitHub Desktop.
Example proofing the sequential processing of es map
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
const es = require('event-stream'); | |
const R = require('ramda'); | |
function getRandomInt(min, max) { | |
var min = Math.ceil(min); | |
var max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min)) + min; | |
} | |
const readable = es.readArray(R.map(R.toString, R.range(1, 5000))); | |
const map = es.map((data, cb) => { | |
const ms = getRandomInt(1000, 5000); | |
setTimeout(() => { | |
console.log('>>>', data, ms) | |
cb(null, data + '\n'); | |
}, ms); | |
}); | |
readable.pipe(map).pipe(process.stdout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment