• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# dezalgo
2
3Contain async insanity so that the dark pony lord doesn't eat souls
4
5See [this blog
6post](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony).
7
8## USAGE
9
10Pass a callback to `dezalgo` and it will ensure that it is *always*
11called in a future tick, and never in this tick.
12
13```javascript
14var dz = require('dezalgo')
15
16var cache = {}
17function maybeSync(arg, cb) {
18  cb = dz(cb)
19
20  // this will actually defer to nextTick
21  if (cache[arg]) cb(null, cache[arg])
22
23  fs.readFile(arg, function (er, data) {
24    // since this is *already* defered, it will call immediately
25    if (er) cb(er)
26    cb(null, cache[arg] = data)
27  })
28}
29```
30