Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/npm/dezalgo
Contain async insanity so that the dark pony lord doesn't eat souls
https://github.com/npm/dezalgo
npm-cli
Last synced: 20 days ago
JSON representation
Contain async insanity so that the dark pony lord doesn't eat souls
- Host: GitHub
- URL: https://github.com/npm/dezalgo
- Owner: isaacs
- License: isc
- Created: 2014-06-30T18:55:33.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2023-04-15T20:45:37.000Z (over 1 year ago)
- Last Synced: 2024-11-14T22:07:32.034Z (28 days ago)
- Topics: npm-cli
- Language: JavaScript
- Homepage:
- Size: 332 KB
- Stars: 89
- Watchers: 24
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-javascript - dezalgo
README
# dezalgo
Contain async insanity so that the dark pony lord doesn't eat souls
See [this blog
post](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony).## USAGE
Pass a callback to `dezalgo` and it will ensure that it is *always*
called in a future tick, and never in this tick.```javascript
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)
})
}
```