Skip to content

Instantly share code, notes, and snippets.

@jschwarty
Created November 9, 2016 01:17
Show Gist options
  • Save jschwarty/5f6332453e16926439b4d6983a57a902 to your computer and use it in GitHub Desktop.
Save jschwarty/5f6332453e16926439b4d6983a57a902 to your computer and use it in GitHub Desktop.
A queue implemented in RxJS that will stream while subscribed and back up while no observers.
class Queue extends Subject<any> {
private items;
add(item) {
if(this.observers.length > 0) {
this.next(item);
} else {
this.items.push(item);
}
}
subscribe(observer) {
let s = super.subscribe(observer);
this.items.forEach(item => this.next(item));
this.items = [];
return s;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment