My RXJS Pipeline is structured as follows:
const logs: number[] = [1, 2, 3, 4];
const url = 'http://some-url-here.com';
const pipeline = from(logs).pipe(
switchMap(logId =>
this.callEndpoint(url, logId).pipe(map(response => response.data)),
),
);
const res = await pipeline.toPromise();
console.log(res);
// The actual function utilizes nestJS http service to reach a URL
callEndpoint(url: string, logId: number) {
const result = Math.random() * 1000;
console.log(`result in callEndpoint: ${result}`);
return of({ data: result });
}
A preview of the code's output can be seen below:
result in callEndpoint: 586.773956063481
result in callEndpoint: 842.136341622411
result in callEndpoint: 964.0849490798163
result in callEndpoint: 598.7596176858414
598.7596176858414
The final number represents the value stored in res
.
Is there a way to consolidate all the successful endpoint calls' results into a single array within the variable res
?