Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 89 题:设计并实现 Promise.race() 代码: #53

Open
DreamLee1997 opened this issue Oct 17, 2019 · 0 comments
Open

第 89 题:设计并实现 Promise.race() 代码: #53

DreamLee1997 opened this issue Oct 17, 2019 · 0 comments

Comments

@DreamLee1997
Copy link
Owner

代码:

let p1 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('success1')
    }, 200)
})
let p2 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('success2')
    }, 100)
})
let p3 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('success3')
    }, 300)
})
let p4 = new Promise((resolve, reject) => {
    setTimeout(() => {
        reject('failed1')
    }, 200)
})
let promises = [p1, p2, p3, p4]

Promise._race = promises = new Promise((resolve, reject) =>{
    promises.forEach((promise)=>{
        promise.then(resolve,reject);
    })
})

输出:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant