0

I am trying to use Bacon stream as never ending loop but it doesn't work.

var Bacon = require('baconjs');

var INTERVAL = 300;

var tickStream = Bacon.interval(INTERVAL);
var isMaster = tickStream.flatMap(function() {
  console.log('I never see the message');
  return Bacon.once('some value');
});

Why don't I see anything in console? How can I fix it?

kharandziuk
  • 12,020
  • 17
  • 63
  • 121

1 Answers1

3

You don't see the value as there are no subscribers in the stream. Bacon only starts listening to events from the source when first subscriber is added (and stops listening to events when the last subscriber is removed).

You can fix this by adding a subscriber, e.g.

var tickStream = Bacon.interval(INTERVAL);
var isMaster = tickStream.flatMap(function() {
  console.log('I never see the message');
  return Bacon.once('some value');
});
isMaster.onValue(function(value) { console.log(value) });
Lautis
  • 626
  • 5
  • 4