如何延迟分叉加入 [英] How to delay forkJoin

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

问题描述

你如何在 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 运算符

use the delay operator withe the pipe operator

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))
 );

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆