let promise wait a couple of seconds before return

后端 未结 4 1864
迷失自我
迷失自我 2021-02-19 09:07

I\'m having a function returning a promise. In this function, we call a third party vender to send some push notification through their server.

it looks like



        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-19 09:31

    Create new promise which will call sendMessage after a timeout.

    apiGetLoggedInUser.then(
      user => {
        return new Promise((resolve, reject) => {
           setTimeout(() => {
              sendMessage(user.name).then(resolve, reject);
           }, 3000)
        });
      }
    )
    

提交回复
热议问题