Last active
January 22, 2018 12:17
-
-
Save coderaiser/d13388cc9f2723dd90f405d420515b99 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 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