How to delay forkJoin

前端 未结 3 1884
情话喂你
情话喂你 2021-01-17 01:01

How would you delay .forkJoin() in rxjs?

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

return forkJoin(
   this.cal         


        
3条回答
  •  孤城傲影
    2021-01-17 01:39

    Maybe this more complete example will help you find the solution you need:

    import { delay } from 'rxjs/operators';
    import { Observable } from "rxjs";
    import { forkJoin } from 'rxjs/observable/forkJoin';
    
    function call1(): Observable {
      return new Observable(observer => {
        setTimeout(_ => {
          observer.next('CALL1');
          observer.complete();
        }, 1000);
      })
    }
    function call2(): Observable {
      return new Observable(observer => {
        setTimeout(_ => {
          observer.next('CALL2');
          observer.complete();
        }, 2000);
      });
    } 
    function call3(): Observable {
      return new Observable(observer => {
        setTimeout(_ => {
          observer.next('CALL3');
          observer.complete();
        }, 3000);
      })
    }
    
    forkJoin(call1(), call2(), call3()).pipe(delay(5000)).subscribe(
      response => console.log(response)
    )
    

提交回复
热议问题