@specialblend/unpromisify
Version:
convert async functions into callback style functions
52 lines (33 loc) • 1.16 kB
Markdown
convert async functions into callback style functions
`npm install @specialblend/unpromisify`
```ecmascript 6
import unpromisify from '@specialblend/unpromisify'
const checkYoSelfFoo = async name => `Hey ${name}, checkYoSelfFoo!`
const checkYoSelfBar = unpromisify(checkYoSelfFoo)
checkYoSelfFoo('@specialblend')
.then(console.log) // => 'Hey @specialblend, checkYoSelfFoo!'
.catch(console.error)
checkYoSelfBar('@specialblend', (err, data) => {
if(err) console.error(err)
console.log(data) // => 'Hey @specialblend, checkYoSelfFoo!'
})
```
```javascript
const unpromisify = require('@specialblend/unpromisify')
function checkYoSelfFoo (name) {
return Promise.resolve('Hey ' + name + ', checkYoSelfFoo!')
}
const checkYoSelfBar = unpromisify(checkYoSelfFoo)
checkYoSelfFoo('@specialblend')
.then(console.log) // => 'Hey @specialblend, checkYoSelfFoo!'
.catch(console.error)
checkYoSelfBar('@specialblend', function (err, data) {
if(err) console.error(err)
console.log(data) // => 'Hey @specialblend, checkYoSelfFoo!'
})
```