Last active
May 12, 2016 13:48
-
-
Save joshwcomeau/cc5eef37e022f4de7070a1b02a1234d9 to your computer and use it in GitHub Desktop.
convert-to-async
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
export const wrapWithPromise = wrappedFunction => (...args) => ( | |
new Promise((resolve, reject) => { | |
wrappedFunction(...args, (err, result) => { | |
return err ? reject(err) : resolve(result); | |
}); | |
}) | |
); | |
export const readFilePromise = wrapWithPromise(fs.readFile); | |
export const writeFilePromise = wrapWithPromise(fs.writeFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment