I've implemented polling with unsubBus "pattern". Can you suggest something better? Pseudo code:
var unsubBus = new Bacon.Bus();
// Poll job status code until it's successful
var succStream = Bacon.interval(pollInterval)
.takeUntil(unsubBus)
.flatMapLatest(function (v) { return this.checkStatus(jobId); })
.filter(function(v) { return v === true; });
// Unsubscribe and do something
succStream.onValue(function (_) { unsubBus.push(true); });
succStream.onValue(function (_) { DO-SOMETHING; });
Running example: http://jsfiddle.net/o8nnmswa/
I couldn't find a nice way to "throw" errors to handle them later. It would be cool to have a succint syntax for the following:
var streamWithPossibleErrors = bus.flatMap(function(v) {
if (v != "bacon") {
return Bacon.sequentially(0, [new Bacon.Error("Error to be reported later")])
}
return v
});
Running example: http://jsfiddle.net/aejfyf7t/