[英]rxjs merge http response
Multiple http requests are concurrent, and the number of concurrent requests can be controlled.多个http请求是并发的,并发请求数可以控制。 After all the requests are completed, data can be merged (data can be ordered or unordered)
完成所有请求后,可以合并数据(数据可以是有序的,也可以是无序的)
from([link, link, link]).pipe(
merge(l => request.get(l)),
// something...
)
return [linkdata, linkdata, linkdata]
Consider implementing it as demonstrated below:考虑实现它,如下所示:
from([link1, link2, link3]).pipe(
mergeMap(request.get, CONCURRENT_NUMBER), // <= limit the number of active inner subscriptions at a time
toArray() // <= transform stream into array prior to completion
)
.subscribe(([result1, result2, result3]) => { })
Seem like you need to use forkJoin好像你需要使用forkJoin
const links = [link1, link2, link3]; // assump `links` is an array of string
forkJoin(
from(links).pipe(
mergeMap((link: string) => {
return http.get(link); // returns an observable
}),
toArray()
)
).pipe(
map(array => array[0]) // data stream is in [[data]] format, you only need head
); // [link1data, link2data, link3data]
I think you are searching for mergeAll
我想你正在寻找
mergeAll
from([link1, link2, link3].map(link => request.get(link))).pipe(
mergeAll(CONCURRENT_NUMBER),
// something like reduce, toArray... to combine the results
).subscribe(console.log);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.