How can I create an observable with a delay

后端 未结 5 1067
醉梦人生
醉梦人生 2020-12-02 13:48

Question

For testing purposes, I\'m creating Observable objects that replace the observable that would be returned by an actual http call with H

5条回答
  •  执念已碎
    2020-12-02 14:45

    What you want is a timer:

    // RxJS v6+
    import { timer } from 'rxjs';
    
    //emit [1, 2, 3] after 1 second.
    const source = timer(1000).map(([1, 2, 3]);
    //output: [1, 2, 3]
    const subscribe = source.subscribe(val => console.log(val));
    

提交回复
热议问题