Skip to content

Commit e7b979b

Browse files
author
James Halliday
committed
moved loop() over to saw.nest
1 parent 1c64e8e commit e7b979b

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

index.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,19 @@ exports.stream = function (em, eventName) {
9595
next();
9696
};
9797

98-
self.loop = function loop (cb) {
98+
self.loop = function (cb) {
9999
var end = false;
100100

101-
var s = Chainsaw.saw(builder, {});
102-
s.on('end', function () {
103-
if (!end) self.loop(cb)
104-
});
105-
106-
var r = builder.call(s.handlers, s);
107-
if (r !== undefined) s.handlers = r;
108-
109-
var ch = s.chain();
110-
ch.vars = vars.store;
111-
cb.call(ch, function () {
112-
end = true;
113-
next();
101+
saw.nest(false, function loop () {
102+
this.vars = vars.store;
103+
cb.call(this, function () {
104+
end = true;
105+
next();
106+
}, vars.store);
107+
this.tap(function () {
108+
if (end) saw.next()
109+
else loop.call(this)
110+
});
114111
}, vars.store);
115112
};
116113

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"url" : "http://substack.net"
2222
},
2323
"dependencies" : {
24-
"chainsaw" : ">=0.0.4",
24+
"chainsaw" : ">=0.0.7",
2525
"put" : ">=0.0.1",
2626
"buffers" : ">=0.0.1"
2727
},

test/binary.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ exports.loop = function () {
360360
}, 500);
361361

362362
Binary.stream(em)
363-
.loop(function (end) {
364-
var vars_ = this.vars;
363+
.loop(function (end, vars) {
364+
assert.ok(vars === this.vars);
365365
this
366366
.word16lu('a')
367367
.word8u('b')
368368
.word8s('c')
369-
.tap(function (vars) {
369+
.tap(function (vars_) {
370370
assert.ok(vars === vars_);
371371
times ++;
372372
if (vars.c < 0) end();

0 commit comments

Comments
 (0)