Skip to content

中断Promise链

依次输出1、2、3

js
new Promise((res, rej) => {
    res(123)
})
.then(() => {
    console.log('1')
})
.then(() => {
    console.log('2')
})
.then(value => {
    console.log('3')
})

只输出1

js
new Promise((res, rej) => {
    res(123)
})
.then(() => {
    console.log('1')
    return new Promise(() => {}) // 返回一个一直pending的Promise,中断Promise链
})
.then(() => {
    console.log('2')
})
.then(value => {
    console.log('3')
})