Skip to content

Instantly share code, notes, and snippets.

@davidecavaliere
Last active January 15, 2020 16:54
Show Gist options
  • Save davidecavaliere/30c44931f720a4870e2a6b61218d9b59 to your computer and use it in GitHub Desktop.
Save davidecavaliere/30c44931f720a4870e2a6b61218d9b59 to your computer and use it in GitHub Desktop.
@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