baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript
https://baconjs.github.io
MIT License
6.47k stars 330 forks source link

`bus.end()` call lost when called synchronously after takeUntil on `bus.mapEnd(null)` #517

Closed Macil closed 9 years ago

Macil commented 9 years ago

This code should print "got value 1" and stop, but instead "got value 1" and "got value 2" are outputted. However, if you add a subscriber to the bus first by adding bus.log(); after defining the bus, it works as expected.

var Bacon = require('baconjs');
var bus = new Bacon.Bus();
var s = Bacon.once(1).merge(Bacon.later(10, 2));
s.takeUntil(bus.mapEnd(null)).onValue(function(value) {
  console.log('got value', value);
  bus.end();
});

Calling bus.end() before there are any subscribers usually does nothing (I'm a little uncomfortable with this, but it's not what this issue is specifically). However, the .takeUntil(bus.mapEnd(null)) does add a subscriber to the bus, so I'd expect the later bus.end() call to work.

Bacon 0.7.41 from NPM

raimohanska commented 9 years ago

Once again, a problem caused by synchronously responding sources, as in #367.

The Bacon.once() stream responds synchroneously, and the onValue function gets served before takeUntil has subscribed to the Bus.

raimohanska commented 9 years ago

Fixed in 0.7.57. There was indeed "one more thing" to fix in the workings of bus.end() when called without subscribers.