Typescript sleep

前端 未结 7 561
后悔当初
后悔当初 2020-11-30 20:02

I\'m developing a website in Angular 2 using Typescript and I was wondering if there was a way to implement thread.sleep(ms) functionality.

My use case

7条回答
  •  既然无缘
    2020-11-30 20:25

    With RxJS:

    import { timer } from 'rxjs';
    
    // ...
    
    timer(your_delay_in_ms).subscribe(x => { your_action_code_here })
    

    x is 0.

    If you give a second argument period to timer, a new number will be emitted each period milliseconds (x = 0 then x = 1, x = 2, ...).

    See the official doc for more details.

提交回复
热议问题