run-duck-run

2.2.0 • Public • Published

🦆 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

Package Sidebar

Install

npm i run-duck-run

Weekly Downloads

99

Version

2.2.0

License

MIT

Unpacked Size

4.64 kB

Total Files

4

Last publish

Collaborators

  • jameskyburz