Consider you have a list
of web addresses:
urls: string[]
You create a set of requests (in this instance, utilizing Angular's HTTPClient.get which gives back an Observable)
const requests = urls.map((url, index) => this.http.get<Film>(url)
The objective is to run these requests concurrently while receiving responses gradually. In simple terms, if there's something like films$: Observable<Film[]>
, I intend for films$
to update step by step with each new response received.
To simulate this scenario, adjust the code snippet above as follows
const requests = urls.map((url, index) => this.http.get<Film>(url).pipe(delay((index + 1)* 1000))
With the updated array of Observable
s mentioned above, data from each request should be retrieved sequentially since they are not all requested simultaneously. Bear in mind that this is just a representation of staggered data arrival times from individual requests. The requests themselves are executed concurrently.
The aim is to refresh the items in films$
every time any of the requests emit a value.