Skip to content

Instantly share code, notes, and snippets.

@sonthonaxrk
Last active October 28, 2015 17:35
Show Gist options
  • Save sonthonaxrk/9caee0ee2005c0398328 to your computer and use it in GitHub Desktop.
Save sonthonaxrk/9caee0ee2005c0398328 to your computer and use it in GitHub Desktop.
sequential-async-recusive-baconjs-queue.js
var pages = new Bacon.Bus();
var next = $("#next").asEventStream('click').map(true);
var pageNo = 0;
pages.flatMapConcat(asyncFunction).zip(next).onValue(value => {
console.log(value);
pages.push(value);
});
pages.push(1);
function asyncFunction(page) {
// Simulating something like an AJAX request
return Bacon.later(1000 + (Math.random() * 3000), Math.random() )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment