Contain async insanity so that the dark pony lord doesn't eat souls
JavaScript
Switch branches/tags
Clone or download
Latest commit d4d3f3f Jun 19, 2015
Permalink
Failed to load latest commit information.
test test that args are handled properly Jun 30, 2014
.travis.yml tap 1.2.0 and travis Jun 1, 2015
LICENSE added explicit license text May 21, 2015
README.md doc Jun 30, 2014
dezalgo.js use wrappy for property transfer Sep 18, 2014
package.json 1.0.3 Jun 19, 2015

README.md

dezalgo

Contain async insanity so that the dark pony lord doesn't eat souls

See this blog post.

USAGE

Pass a callback to dezalgo and it will ensure that it is always called in a future tick, and never in this tick.

var dz = require('dezalgo')

var cache = {}
function maybeSync(arg, cb) {
  cb = dz(cb)

  // this will actually defer to nextTick
  if (cache[arg]) cb(null, cache[arg])

  fs.readFile(arg, function (er, data) {
    // since this is *already* defered, it will call immediately
    if (er) cb(er)
    cb(null, cache[arg] = data)
  })
}