Last active
December 21, 2017 03:24
-
-
Save davidicus/689091cfd9ffef320a83b35c7b47dac6 to your computer and use it in GitHub Desktop.
Make async code return a promise
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 promisify = func => (...args) => { | |
return new Promise((resolve, reject) => { | |
func(...args, (err, result) => { | |
err ? reject(err) : resolve(result); | |
}) | |
}); | |
} | |
// const delay = promisify((d, cb) => setTimeout(cb, d)) | |
// delay(2000).then(() => console.log('Hi!')) -> Promise resolves after 2s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment