Created
November 9, 2016 01:17
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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