Skip to content

Instantly share code, notes, and snippets.

@myndzi
Last active August 6, 2017 20:08
Show Gist options
  • Save myndzi/144f6e3513c0c1554cde878ea3344306 to your computer and use it in GitHub Desktop.
Save myndzi/144f6e3513c0c1554cde878ea3344306 to your computer and use it in GitHub Desktop.
const Promise = require("bluebird");
const fs = Promise.promisifyAll(require('fs'))
function getNumbers() {
var fileNumbers = [];
for(var n = 0; n < 10; n++){
fileNumbers.push(n);
}
return fileNumbers;
}
Promise.all(getNumbers())
.mapSeries(function (number) {
//I'm using setTimeout to emulate the processing time of the real scrip
return Promise.delay(3000).then(function() {
return writeMyFile(number);
});
});
function writeMyFile(fn){
//I'm using writeFile here but Jimp uses writeFileStream and writes a buffer to it...
//the buffer doesn't return which is the same issue here
return fs.writeFileAsync("set\\" + fn + ".txt", "Hey there!")
.then(function () {
console.log("The file was saved!"))
})
.catch(function (err) {
console.log(err)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment