]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/dezalgo/README.md
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / dezalgo / README.md
1 # dezalgo
2
3 Contain async insanity so that the dark pony lord doesn't eat souls
4
5 See [this blog
6 post](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony).
7
8 ## USAGE
9
10 Pass a callback to `dezalgo` and it will ensure that it is *always*
11 called in a future tick, and never in this tick.
12
13 ```javascript
14 var dz = require('dezalgo')
15
16 var cache = {}
17 function 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 ```