let promise wait a couple of seconds before return

后端 未结 4 1873
迷失自我
迷失自我 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:16

    Insert another promise in the chain which delays the next one:

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

提交回复
热议问题