1

Please explain why the below stream overflows?

infiniteStream = function(page) {
  return Bacon.fromBinder(function(sink) {
    sink(page);
    sink(new Bacon.Next(function() { return infiniteStream(page + 1); }));
  }).flatMapConcat(function(v) {
    return v;
  });
};

fiveStream = function(count) {
  return Bacon.fromArray([count, count, count, count, count]);
};

stream = infiniteStream(1).flatMapConcat(function(v) {
  return fiveStream(v);
});

// fine
stream.take(6).log();

// Error: maximum call stack exceeded
stream.take(7).log();

I need an infinite stream, I can map to some values, I want to use take(10) to pull as needed, or I want to end this stream whenever some specific value is reached, eg:

stream = stream.withHandler(function(v) {
  if (v.hasValue() && v.value() == "link50") {
    this.push(new Bacon.Error("bad link"));
    return this.push(new Bacon.End());
  } else {
    return this.push(v);
  }
});
OlliM
  • 7,023
  • 1
  • 36
  • 47
user3995789
  • 3,452
  • 1
  • 19
  • 35
  • Possible duplicate of [Bacon.js Maximum Call Stack Exceeded](https://stackoverflow.com/questions/20304334/bacon-js-maximum-call-stack-exceeded) – Paul Sweatte Jul 20 '17 at 15:07

0 Answers0