Projekt

Obecné

Profil

Stáhnout (675 Bajtů) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
# iferr
2
3
Higher-order functions for easier error handling.
4
5
`if (err) return cb(err);` be gone!
6
7
## Install
8
```bash
9
npm install iferr
10
```
11
12
## Use
13
14
### JavaScript example
15
```js
16
var iferr = require('iferr');
17
18
function get_friends_count(id, cb) {
19
  User.load_user(id, iferr(cb, function(user) {
20
    user.load_friends(iferr(cb, function(friends) {
21
      cb(null, friends.length);
22
    }));
23
  }));
24
}
25
```
26
27
### CoffeeScript example
28
```coffee
29
iferr = require 'iferr'
30
31
get_friends_count = (id, cb) ->
32
  User.load_user id, iferr cb, (user) ->
33
    user.load_friends iferr cb, (friends) ->
34
      cb null, friends.length
35
```
36
37
(TODO: document tiferr, throwerr and printerr)
38
39
## License
40
MIT