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

Promise.all 是在所有promise对象都变为resolve或者只要有一个变为reject时,才会去调用.then ! #24

Open
xiaoyann opened this issue Dec 17, 2015 · 1 comment

Comments

@xiaoyann
Copy link

原文:
Promise.all 接收一个 promise对象的数组作为参数,当这个数组里的所有promise对象全部变为resolve或reject状态的时候,它才会去调用 .then 方法。

而实际上应该是:
Promise.all 是在所有promise对象都变为resolve或者只要有一个变为reject时,才会去调用.then

先抛出警告:2,再输出:p3
    var p1 = Promise.resolve(1);
    var p2 = Promise.reject(2);
    var p3 = new Promise(function(resolve, reject) {
        setTimeout(function() {
            console.log('p3')
            resolve(3);
        }, 500);
    });

    p3.then(function(res) {
        console.log('p3')
    });

    Promise.all([p1, p2, p3]).then(function(res) {
        console.log(res)
    }, function(err) {
        console.warn(err)
    });
@ghost
Copy link

ghost commented Apr 26, 2017

说白了就是亦或的关系,有且只有一个为假,则全部为假。不管是假是真都会调用.all这个对象的then就会被调用

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