Created
October 23, 2017 06:18
-
-
Save jessecogollo/6f2ed39d646a3a76bffdb55f33d01b7e to your computer and use it in GitHub Desktop.
callbackify
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
'use strict'; | |
const { | |
callbackify | |
} = require('util'); | |
const asyncFn = async function (text) { | |
if (text === true) { | |
return await Promise.reject(`parce, no me mande un true !!!`); | |
} | |
return await Promise.resolve(`Hola, ${text}`); | |
}; | |
const callbackAsyncFn = callbackify(asyncFn); | |
module.exports = { | |
asyncFn, | |
callbackAsyncFn | |
}; |
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
'use strict'; | |
const { | |
asyncFn, | |
callbackAsyncFn | |
} = require('./modules/util'); | |
callbackAsyncFn('jesse callback', (error, result) => { | |
if(error) { | |
console.log('error callback', error.message || error); | |
}; | |
console.log('callback', result); | |
}); | |
asyncFn('jesse promise').then((result) => { | |
console.log('promise', result); | |
}).catch((error) => { | |
console.log('error promise', error.message || error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment