Skip to content

Instantly share code, notes, and snippets.

@coderaiser
Last active January 22, 2018 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderaiser/d13388cc9f2723dd90f405d420515b99 to your computer and use it in GitHub Desktop.
Save coderaiser/d13388cc9f2723dd90f405d420515b99 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const readFile = promisify(fs.readFile);
readFile('./hello', 'utf8').then(console.log);
// outputs
'world';
function promisify(fn) {
return (...a) => {
return new Promise((resolve, reject) => {
fn(...a, (e, a) => {
if (e)
throw e;
resolve(a);
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment