Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Last active May 12, 2016 13:48
Show Gist options
  • Save joshwcomeau/cc5eef37e022f4de7070a1b02a1234d9 to your computer and use it in GitHub Desktop.
Save joshwcomeau/cc5eef37e022f4de7070a1b02a1234d9 to your computer and use it in GitHub Desktop.
convert-to-async
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