Home Js模拟ruby的sleep
Post
Cancel

Js模拟ruby的sleep

这个可以

      sleep(n_seconds){
        return new Promise(resolve => setTimeout(resolve, n_seconds * 1000))
      },

      async init() {
           await sleep(3)
      }

这个也行: (注意 setTimeout中的resolve的写法。。。)

        return new Promise( (resolve, reject) => {
          setTimeout( () => {
            resolve()
          }, n_seconds * 1000)
        })

This post is licensed under CC BY 4.0 by the author.
Contents