Promise.finally

时间:2020-01-23 23:01:11   收藏:0   阅读:108
const Gen = (time) => {
  return new Promise((resolve, reject) => {
    setTimeout(function () {
      if(time < 500) {
        reject(time)
      } else {
        resolve(time)
      }
    },time)
  })
}

Gen(Math.random() * 1000)
.then(val => console.log(‘resolve‘, val))
.catch(err => console.log(‘reject‘, err))
.finally(() => { console.log(‘finish‘)})

 

原文:https://www.cnblogs.com/qjb2404/p/12231606.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!