Skip to content

Instantly share code, notes, and snippets.

@fxfactorial
Last active July 16, 2017 12:04
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 fxfactorial/7f91190227501bafdee347c361a83f28 to your computer and use it in GitHub Desktop.
Save fxfactorial/7f91190227501bafdee347c361a83f28 to your computer and use it in GitHub Desktop.
const event_emitter = require('events');
class PhotoAnalyzer extends event_emitter {
constructor() {
super();
this.times =
new Array(10).fill(undefined).map(() => Math.floor(Math.random() * 10000));
}
};
const download = new PhotoAnalyzer;
download.on('download-piece-complete', function(part_index) {
console.log(this.times[part_index]);
});
Promise.all(
download.times.map((delay, i) => {
return (new Promise(accept => {
setTimeout(() => accept(i), delay);
})).then(spot => download.emit('download-piece-complete', spot));
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment