Created
January 8, 2018 06:21
-
-
Save ashrafuzzaman/6af06dcd2bfb38c4a3d00a4fdef691fc to your computer and use it in GitHub Desktop.
Promise each
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
'use strict'; | |
const Promise = require('bluebird'); | |
let _updateResults = () => { | |
let promises = []; | |
for (let offset = 0; offset < 10; offset += 1) { | |
promises.push(new Promise(resolve => _updateResultsInChunk(offset).then(resolve))); | |
} | |
return Promise.each(promises, () => { | |
console.log('Done'); | |
}); | |
}; | |
let _updateResultsInChunk = (offset) => { | |
console.log('Before Resolve ::' + offset); | |
return new Promise(resolve => { | |
console.log('1. Resolve ::' + offset); | |
resolve(offset); | |
}).then(() => new Promise(resolve => { | |
console.log('2. Resolve ::' + offset); | |
resolve(offset); | |
})); | |
}; | |
_updateResults().then(() => { | |
process.exit(0); | |
}).catch((err) => { | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment