mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-07-16 20:06:23 +00:00
Vendorize queueing-subject
This commit is contained in:
26
src/app/services/queueing-subject.ts
Normal file
26
src/app/services/queueing-subject.ts
Normal file
@ -0,0 +1,26 @@
|
||||
// Based on https://github.com/ohjames/queueing-subject
|
||||
|
||||
import { Subject, Subscriber, Subscription } from 'rxjs';
|
||||
|
||||
export class QueueingSubject<T> extends Subject<T> {
|
||||
private queuedValues: T[] = [];
|
||||
|
||||
next(value: T): void {
|
||||
if (this.closed || this.observers.length) {
|
||||
super.next(value);
|
||||
} else {
|
||||
this.queuedValues.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
_subscribe(subscriber: Subscriber<T>): Subscription {
|
||||
const subscription = super._subscribe(subscriber);
|
||||
|
||||
if (this.queuedValues.length) {
|
||||
this.queuedValues.forEach(value => super.next(value));
|
||||
this.queuedValues.splice(0);
|
||||
}
|
||||
|
||||
return subscription;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user