I have a simple Rxjs timer that keeps going until a notifier emits something, very basic till here.
enum TimerResult = {
COMPLETE,
ABORTED,
SKIPPED
};
_notifier: Subject<TimerResult> = new Subject();
notifier$: Observable<TimerResult> = this._notifier.asObservable();
simpleTimer$ = interval(1000);
startTimer(): Observable<number> <-- **here I want a timerResult** {
return simpleTimer$.pipe(
tap(()=>doSomethingBeautifulWhileRunning),
takeUntil(this.notifier$)
)
}
What I'd like to achieve is to get the value emitted by notifier as a result.
I don't need intermediate values , I need only to know when it completes and with what result.
simpleTimer$.pipe(
tap(()=>doSomethingBeautifulWhileRunning),
last(),
takeUntil(this.notifier$)
).subscribe((result)=>{
// Here, of course, I get the last value
// I need instead the value coming from notifier$
});
I tried a lot of possible solutions with Rx operators but none of them worked as expected. The only one I found that produces an acceptable result (but imho very very dirty) was this:
startTimer(): Observable<TimerResult>{
simpleTimer$.pipe(...).subscribe(); <-- fire the timer, automatically unsubscribed by takeUntil
return this.notifier$.pipe(first());
}
What's the best "Rx" way to obtain this? I hope I have been clear enough, any help is super appreciated :)