I have a code that emits a new values :
function newValues(): Observable<any> {
const data$ = new BehaviorSubject<any>({});
setInterval((x) => {
data$.next(this.getNewData());
}, 1000);
return data$.asObservable();
}
so this way by subscribing to newValues().subscribe()
I can receive a new values all the time.
But I think it is not the best way of doing this so I looked at this and so my code became like this:
function newValues(): Observable<any> {
const data$ = new BehaviorSubject<any>({});
defer(() => data$.next(this.getNewData()))
.pipe(
repeatWhen(notifications => notifications.pipe(delay(1000)))
);
return data$.asObservable();
}
However it is seems like the code not working now, after receiving the first value no emissions is taking place.
Any ideas how to fix?
UPDATE:
@evantha suggest to use interval for that use case, I just wonder does that mean that defer....repeatWhen....delay
won't work for that use-case?