Last active
August 6, 2017 19:59
-
-
Save myndzi/4e08254586ac7c1bf7a87f1fb1506052 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')) | |
const getNumbers = () => new Promise((resolve, reject) => { | |
var fileNumbers = []; | |
for(var n = 0; n < 10; n++){ | |
fileNumbers.push(n); | |
} | |
resolve(fileNumbers); | |
}); | |
Promise.all(getNumbers()) | |
.mapSeries((myNumbers) => | |
Promise.delay(3000).then(() => writeMyFile(myNumbers)) | |
); | |
var writeFileAsync = Promise.promisify(fs.writeFile, { context: fs }); | |
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 writeFileAsync("set\\" + fn + ".txt", "Hey there!") | |
.then(() => console.log("The file was saved!")) | |
.catch(err => console.log(err)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment