Created
November 2, 2016 16:08
-
-
Save ste2425/a284ead2ac823e61cd2a07ac237b7176 to your computer and use it in GitHub Desktop.
Little promisify helper
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
let promisify = (fn) => (...args) => | |
new Promise((rCB, eCB) => | |
fn(...args, (e, r) => { | |
if (e) | |
eCB(e); | |
else | |
rCB(r); | |
})); | |
promisify(sass.render({ | |
file: 'myFile.scss' | |
)) | |
.then(r => promisify(mkdir)(destPathFolder).then(x => r.css)) | |
.then(css => promisify(fs.writeFile)(destPath, css)) | |
.then(d => console.log('All Done!')) | |
.catch(e => console.error(`Proccess error: ${e}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found a flaw, if you provide the call back when calling the promisified function it will still return a promise. However the promise will never resolve, instead the callback will run like it wasn't promisified in the first place.
I guess you could check the last argument passed in to see if its a function and make assumptions based on that but that seems painful.