How to create an RXjs RetryWhen with delay and limit on tries

You need to apply the limit to the retry signal, for instance if you only wanted 10 retries: loadSomething(): Observable<SomeInterface> { return this.http.get(this.someEndpoint, commonHttpHeaders()) .retryWhen(errors => // Time shift the retry errors.delay(500) // Only take 10 items .take(10) // Throw an exception to signal that the error needs to be propagated .concat(Rx.Observable.throw(new Error(‘Retry limit exceeded!’)) … Read more

Angular 2 cache observable http result data [duplicate]

If you lean into observables as a means of sharing data, you can adopt the following approach: import { Injectable } from ‘@angular/core’; import { HttpClient } from ‘@angular/common/http’; import { Observable, ReplaySubject } from ‘rxjs’; import { SomeModel } from ‘path/to/it’; @Injectable({ providedIn: ‘root’ }) export class CachedService { private dataSubject = new ReplaySubject<SomeModel>(1); … Read more

Difference between .unsubscribe to .take(1)

Each serves a different purpose so it’s hard to compare them. In general if you take this source: const source = range(1,3); … and consume it with subscribe() followed immediately by unsubscribe(): source.subscribe( console.log, undefined, () => console.log(‘complete’) ).unsubscribe(); … then all values from source are going to be emitted even though we called unsubscribe() … Read more

Why is java.util.Observable not an abstract class?

Quite simply it’s a mistake that Observable is a class at all, abstract or otherwise. Observable should have been an interface and the JDK should have provided a convenient implementation (much like List is an interface and ArrayList is an implementation) There are quite a few “mistakes” in java, including: java.util.Stack is a class, not … Read more

Angular 2: Convert Observable to Promise

rxjs7 lastValueFrom(of(‘foo’)); https://indepth.dev/posts/1287/rxjs-heads-up-topromise-is-being-deprecated rxjs6 https://github.com/ReactiveX/rxjs/issues/2868#issuecomment-360633707 Don’t pipe. It’s on the Observable object by default. Observable.of(‘foo’).toPromise(); // this rxjs5 import ‘rxjs/add/operator/toPromise’; import ‘rxjs/add/operator/map’; … this._APIService.getAssetTypes() .map(assettypes => { this._LocalStorageService.setAssetTypes(assettypes); }) .toPromise() .catch(err => { this._LogService.error(JSON.stringify(err)); });