Skip to content

Instantly share code, notes, and snippets.

@ataube
Created March 3, 2017 18:41
Show Gist options
  • Save ataube/f2fcf05fccedc5bb52319f12815e6d0d to your computer and use it in GitHub Desktop.
Save ataube/f2fcf05fccedc5bb52319f12815e6d0d to your computer and use it in GitHub Desktop.
Example proofing the sequential processing of es map
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