Seeking a replacement for observable, subject, or event emitter that allows only one subscription at a time. The first subscriber should have priority to execute its subscribe function, with subsequent subscribers waiting their turn until the first unsubscribes.
Is there an existing method within observable, subject, or event emitter that supports this behavior, or is there a replacement available that can achieve this functionality?
Alternatively, if there is a technique to detect when a subscriber subscribes or unsubscribes from our target emitter, we could implement this using access modifiers and a boolean flag.
I am currently experimenting with the following code:
private OpenDialogEmitter = new EventEmitter();
private isFirstFetch: boolean = true;
getDialogEmitter(): EventEmitter<{}> {
if (this.isFirstFetch) {
this.isFirstFetch = false;
return this.OpenDialogEmitter;
}
return null;
}
setFirstFetch() {
this.isFirstFetch = true;
}
We need to call setFirstFetch() in the service whenever someone unsubscribes to make the observable available again.
Is there a more effective and built-in approach to achieving this goal?