run-duck-run
v2.2.0
Published
A generator run function
Downloads
561
Maintainers
Readme
🦆 run-duck-run 🦆
A generator function runner
usage
function * foo () {
yield (cb) => setTimeout(cb, 1000)
console.log('done cb')
}
const run = require('run-duck-run')
run(foo, (err) => {
if (err) {
console.error(err)
} else {
console.log('all good')
}
})()
// done cb
function * foo () {
yield new Promise((resolve, reject) => {
setTimeout(resolve, 1000)
})
console.log('done promise')
}
const run = require('run-duck-run')
run(foo, (err) => { })()
// done promise
yield supports thunks and promises.
Why?
If you find a pattern where error handling can all be done in one place....
When writing http routes, error handling is often performed in multiple places....
Check out server-base for an example of using this module.
license
MIT