Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ logs
# Dependency directory
node_modules
bower_components

.idea
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function trueFn() { return true; }

// Globals
var toUpdate = [];
var toEnd = [];
var inStream;
var order = [];
var orderNextIdx = -1;
Expand Down Expand Up @@ -696,6 +697,9 @@ function flushUpdate() {
var nextUpdateFn = stream.updaters.shift();
if (nextUpdateFn && stream.shouldUpdate) nextUpdateFn(stream);
}
while (toEnd.length > 0) {
toEnd.shift()(true);
}
flushingUpdateQueue = false;
}

Expand All @@ -715,6 +719,8 @@ function updateStreamValue(n, s) {
flushingStreamValue = false;
} else if (inStream === s) {
markListeners(s, s.listeners);
} else if (inStream.end === s) {
toEnd.push(inStream.end);
} else {
updateLaterUsing(function(s) { updateStreamValue(n, s); }, s);
}
Expand Down
26 changes: 26 additions & 0 deletions test/delayed-stream-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var assert = require("assert");
var R = require("ramda");

var flyd = require("../lib");

describe("ending a stream", function () {
it("delays ending the current stream until dependents have been updated", function () {
var stream = flyd.stream(1);
var count = 0;
stream.map(function () {
var s1 = stream.map(R.add(1));
var s2 = stream.map(R.add(2));
flyd
.combine(
function (s1, s2, self) {
self(s1() + s2());
self.end(true);
},
[s1, s2],
)
// was not called prior to #229
.map(function () { count++ });
});
assert.equal(count, 1);
});
});