Last active
January 15, 2020 16:54
-
-
Save davidecavaliere/30c44931f720a4870e2a6b61218d9b59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class UserService { | |
private cached$: ReplaySubject<any> = new ReplaySubject(1, 2500); | |
constructor(private _client: HttpClient) {} | |
public findAll(id): Observable<any> { | |
const req = this._client.get(`https://reqres.in/api/users?page=${id}`).pipe( | |
tap((data) => { | |
this.cached$.next(data); | |
}) | |
); | |
return race(this.cached$, req); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment