I want to find an observable,subject or event emitter replacement which supports one and only one subscription at any given time. i.e. the first one to get a subscription will have the right to execute its subscribe's body and when it unsubscribes itself then any next subscriber would be allowed to proceed.
Is there currently any method inside observable, subject or event emitter which supports this functionality or a replacement available which can allow this behavior.
Alternatively if there is some technique with which I can perform some functionality when ever some one subscribes/unsubscribes from our target emitter then I can perform this functionality using access modifier and a boolean.
Currently I am trying something like this:
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;
}
When ever some one unsubscribes it has to mark observable available again by calling setFirstFetch() method inside service.
Is there any better and built in approach?