Skip to content

Instantly share code, notes, and snippets.

@kharandziuk
Last active April 7, 2017 15:06
Show Gist options
  • Save kharandziuk/f90cf6c44dbfcf23bbf569587c55685c to your computer and use it in GitHub Desktop.
Save kharandziuk/f90cf6c44dbfcf23bbf569587c55685c to your computer and use it in GitHub Desktop.
const scramjet = require("scramjet");
const {getAPI, insertDB} = require('./io-simulators')
const ROWS = 1000
// build a stream of indexes
new scramjet.DataStream({
read() {
this.offset = (this.offset || 0);
this.push(this.offset);
this.offset += ROWS ;
}
})
// map indexes to API responses
.map(i => getAPI(i, ROWS))
.flatMap((i) => i)
// filter out the id's containing "3"
.filter(function(item) {
return (""+item.id).indexOf('3') > -1
})
// add timestamp to id's containing "9"
.map(function(item) {
if ((""+item.id).indexOf('9') > -1) {
return Object.assign(item, {timestamp: Date.now()})
} else {
return item
}
})
// write to database
· .accumulate(
function(insert, item) {
return insert(item)
},
insertDB
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment