I have a simple HTTP call:
getContributors(pageNumber): Observable<any> {
const url = `${this.apiBaseUrl}/orgs/angular/public_members?&page=${pageNumber}`;
const requestOptions = this.getRequestOptions();
return this.http.get(url, requestOptions);
}
the call is made within a ngrx effect
.
...
return this.contributorsService.getContributors(payload.pageNumber)
.delay(new Date(Date.now() + Math.random() * 500))
... // mergeMap etc. here
However, while the HTTP call returns an array of multiple values, they're in any case emitted all at once.
Am I misunderstanding the purpose of delay()
operator (and in this case, how do I achieve the expected result?) or am I using it the wrong way?
Note: I imported the augmentation import 'rxjs/add/operator/delay';
UPDATE: to clarify, the expected result is: I want the array to be split and each single value within the array to be emitted separately at a given (constant) time
UPDATE 2: so, the array is actually split by
.flatMap(data => Observable.from(data))
In fact, If
.do(value => console.log(value))
each value is printed individually.
However, if instead of .do(....)
I put
.delay(3000)
.do(() => console.log(new Date())
I can see the delay is not respected at all (except for the fact it actually awaits 3000 to emit all the values in a sequence with no delay - in a row, i.e. multiple console.logs)