Promise.all()的RxJs等效项是什么,从而只有在解决所有诺言后,then块才会执行?
const request1 = this.http.get('/api/hello').toPromise() // returns a promise
const request2 = this.http.get('/api/there').toPromise() // returns a promise
Promise.all([request1, request2]).then(([response1, response2]) => {
// executes if/when ALL the promises resolve
console.log('response1', response1);
console.log('response2', response2);
}).catch(err => {
// executes if ANY ONE of the promises fail / reject
console.log('err', err);
})
那么RxJ中的等效方法是什么?谢谢
答案 0 :(得分:3)
您可以使用forkJoin
当您有一组可观测值和 只关心每个的最终发射值。你可以用这个 操作员发出多个请求。
从“ rxjs”导入{forkJoin,Observable} ;
用法
/Users/<my_username>/.rvm/gems/ruby-2.4.2/gems/bundler-1.16.6/lib/bundler/rubygems_integration.rb:462:in `block in replace_bin_path': can't find executable backup for gem backup. backup is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)