run-duck-run

A generator run function

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
run-duck-run
022.2.04 years ago6 years agoMinified + gzip package size for run-duck-run in KB

Readme

🦆 run-duck-run 🦆
A generator function runner
js-standard-style build status npm downloads Greenkeeper badge
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