在 http 请求结束时执行额外的 observable/promise
execute extra observable/promise at the end of the http request
我有一个拦截器,当请求从服务器返回时我需要chain/execute一个promise/observable。我如何在 rxjs 6 中执行此操作?
intercept(): Observable<HttpEvent<any>> {
return next.handle(request)[DO-SOMETHING]
}
如需修改http事件:
return next.handle(request).pipe(
mergeMap(request => yourPromiseOrObservable));
mergeMap
是做什么的?
Projects each source value to an Observable which is merged in the output Observable.
如果不需要修改http事件:
return next.handle(request).pipe(
tap(request => yourPromise.then(_ => ;)));
tap
是做什么的?
Perform a side effect for every emission on the source Observable, but return
an Observable that is identical to the source.
或者,如果您需要等待承诺但不修改请求:
return next.handle(request).pipe(
delayWhen(request => from(yourPromise)));
delayWhen
是做什么的?
Delays the emission of items from the source Observable by a given time span determined by the emissions of another Observable.
我有一个拦截器,当请求从服务器返回时我需要chain/execute一个promise/observable。我如何在 rxjs 6 中执行此操作?
intercept(): Observable<HttpEvent<any>> {
return next.handle(request)[DO-SOMETHING]
}
如需修改http事件:
return next.handle(request).pipe(
mergeMap(request => yourPromiseOrObservable));
mergeMap
是做什么的?
Projects each source value to an Observable which is merged in the output Observable.
如果不需要修改http事件:
return next.handle(request).pipe(
tap(request => yourPromise.then(_ => ;)));
tap
是做什么的?
Perform a side effect for every emission on the source Observable, but return an Observable that is identical to the source.
或者,如果您需要等待承诺但不修改请求:
return next.handle(request).pipe(
delayWhen(request => from(yourPromise)));
delayWhen
是做什么的?
Delays the emission of items from the source Observable by a given time span determined by the emissions of another Observable.