-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (40 loc) · 691 Bytes
/
index.js
File metadata and controls
43 lines (40 loc) · 691 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
39
40
41
42
43
module.exports = function (opt) {
opt = opt || { debug: true }
var debug = opt.debug
return function (f, back) {
var api = {
next: function (err, data) {
if (err) {
_debugOut(err)
fx.throw(err)
}
step(data)
},
nextOne: function (data) {
step(data)
}
}
var fx = f(api)
step()
function step(data) {
setTimeout(function () {
try {
var c = fx.next(data)
if (c.done == true)
_back(null, c.value)
} catch (err) {
_debugOut(err)
_back(err)
}
}, 0)
}
function _back(err, data) {
if (back != null)
back(err, data)
}
function _debugOut(err) {
if (debug)
console.error(err)
}
}
}