看过不少网友的文章, 有各种方法, 但我想要的是一个能线性执行的sleep函数.
     /*  *
     * 等待指定的时间
     * @param ms
       */  
    static async sleep(ms: number) {
          return   new  Promise((resolve) =>  {
            setTimeout(()  =>  {
                resolve( '' );
            }, ms)
        });
    } 
调用方法:
 async test() {
      //   等待500毫秒后再执行同步 
    await sleep(500 );
    console.log( '123' );
} 
查看更多关于TypeScript 实现 sleep 函数的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did223521