-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherr-example.js
More file actions
39 lines (33 loc) · 789 Bytes
/
err-example.js
File metadata and controls
39 lines (33 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var c = require('./')
var myFn = c.either(
function onErr (err) {
return c.of(err + ' baaaa')
},
function onData (data) {
return c.of('ok')
}
)
myFn(someIO('woooo'))(function (err, done) {
console.log('it worked...', err, done)
// it worked... null ok
})
myFn(ioError('booo'))(function (err, ok) {
console.log('err result...', err, ok)
// err result... null Error: booo baaaa
})
function someIO (data, cb) {
if (!cb) return function (_cb) {
return someIO(data, _cb)
}
process.nextTick(function () {
cb(null, data)
})
}
function ioError (data, cb) {
if (!cb) return function (_cb) {
return ioError(data, _cb)
}
process.nextTick(function () {
cb(new Error('' + data))
})
}