Skip to content

Instantly share code, notes, and snippets.

@blueskyfish
Created February 19, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blueskyfish/9a6db54a0f67aade295cd7646e280911 to your computer and use it in GitHub Desktop.
Save blueskyfish/9a6db54a0f67aade295cd7646e280911 to your computer and use it in GitHub Desktop.
Collection of Subscription
import { SubscriptionLike } from 'rxjs';
export class SubscriberList implements SubscriptionLike {
private mList: SubscriptionLike[] = [];
private mClosed = false;
get closed(): boolean {
return this.mClosed;
}
add(s: SubscriptionLike): SubscriptionLike {
if (s != null) {
this.mList.push(s);
}
return s;
}
unsubscribe(): void {
this.mClosed = true;
this.mList.forEach(s => {
if (!s.closed) {
s.unsubscribe();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment