本文介绍了如何延迟forkJoin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何在rxjs中延迟.forkJoin()?

How would you delay .forkJoin() in rxjs?

这是我所需要的,但是想要使用 delay()算什么?

Here is what I've got but want to use delay() operator with that?

return forkJoin(
   this.call1(),
   this.call2(),
   this.call3()
 );

到目前为止,我知道了:

So far I got this:

return of(null).pipe(
  delay(5000),
  switchmap(() => this.call1()),
  switchmap(() => this.call2()),
  switchmap(() => this.call3()))
);

那是可行的,但是我想使用forkJoin,我尝试了另一种解决方案

That is worked but I would like to use forkJoin, i tried the other soluton

return forkJoin(
   of(this.call1()).pipe(delay(5000)),
   of(this.call2()).pipe(delay(5000)),
   of(this.call3()).pipe(delay(5000))
 );

但似乎无法正常工作.

推荐答案

delay运算符与pipe运算符

import { delay, take } from 'rxjs/operators';
import { forkJoin } from 'rxjs/observable/forkJoin';
import { of } from 'rxjs/observable/of';

return forkJoin(
   of(call1()).pipe(delay(1000)),
   of(call2()).pipe(delay(2000)),
   of(call3()).pipe(delay(1000))
 );

这篇关于如何延迟forkJoin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 20:11