Last active
August 6, 2017 20:08
-
-
Save myndzi/144f6e3513c0c1554cde878ea3344306 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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