paldepind / flyd

The minimalistic but powerful, modular, functional reactive programming library in JavaScript.
MIT License
1.56k stars 84 forks source link

Wrong chain + setImmediate behavior #195

Closed jakubmazanec closed 3 years ago

jakubmazanec commented 5 years ago

I have the following code, taken from the test chain returns stream with result from all streams created by function:

var result = [];
function f(v) {
  var s = stream();
  setImmediate(function() {
    s(v + 1)(v + 2)(v + 3);
  });
  return s;
}
var s = stream();
flyd.map(function(v) {
  result.push(v);
}, flyd.chain(f, s));
s(1)(3)(5);
setImmediate(function() {
  console.log(); // -> [6, 7, 8]
});

According to the test, the console.log output should be [2, 3, 4, 4, 5, 6, 6, 7, 8], but I got [6, 7, 8]. I think there may be an issue with the first setImmediate, but I can't put my finger on it. Any thoughts?

nordfjord commented 5 years ago

Thank you for raising this.

The test should be failing.

but because this happens asynchronously and I omitted the done callback the exception is thrown after the test is marked green so it's not raised.

I'll submit a PR to fix this.

It will involve changing things slightly as it's expected behaviour based on the code that we only get 6, 7, 8