Last active
July 16, 2017 12:04
-
-
Save fxfactorial/7f91190227501bafdee347c361a83f28 to your computer and use it in GitHub Desktop.
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 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