angular - 角度 4 顺序异步 http 请求,错误响应取消
问题描述
我正在尝试使用HttpClient和Observable.forkJoin进行 3 个顺序和异步(非并行)请求。
到目前为止,这是它的外观,首先是fileOperations数组:
requestPayloadObjects:any[];//array of objects sent to the same request
//... after the array was built
this.requestPayloadObjects.forEach( ( payloadObject:any,i:number )=> {
//_uploadApi.postDoc returns an http observable
fileOperations.push( this._uploadApi.postDoc( payloadObject ) );
});
然后在我有一个可观察的数组之后,我使用Observable.forkJoin
// parallel subscriptions, all 3 observables are subscribed to asyncly
Observable.forkJoin(fileOperations).subscribe((res:any)=> {
// If all http calls succeeded you get here
},(err:any)=> {
// If 1 of all 3 that were sent failed you get here
});
但是我想要的是:
// NONE-parallel subscription
Observable.forkJoin(fileOperations).subscribe((res:any)=> {
// If all http calls succeeded you get here
},(err:any)=> {
// If 1 failed, you get here, but you do not send the others
});
我确定 Observable.forkJoin 不是实现此目的的 Observable 方法,但它是什么?如何进行非并行订阅,只有在前一个成功的情况下才会继续下一个?使用 Observables 执行此操作的正确方法是什么?
解决方案
我想concatAll
这就是你要找的。查看它的rxjs 文档。
推荐阅读
- ios - 如何在 Apple-app-site-association 中为不同组件指定路径
- regex - 正则表达式匹配所有单词对
- macos - MacVim 和终端 Vim 上的 Vim Devicons 图标故障
- javascript - 在 Javascript 中递归地运行一个函数
- android - Android:创建类似于系统切换的视图
- sql - 展平两个重复的结构列,并与其中一个在 BigQuery 中转置
- r - 使用 RSelenium 在网页上查找元素的问题
- python - 如何使用硒直接将 G 响应传递给验证码?
- replace - 替换功能中的coldfusion错误
- python - 如何使用 python、selenium 在 Mac 上设置焦点?