{"action":"opened","issue":{"url":"https://api.github.com/repos/itkasumy/Blog/issues/50","repository_url":"https://api.github.com/repos/itkasumy/Blog","labels_url":"https://api.github.com/repos/itkasumy/Blog/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/itkasumy/Blog/issues/50/comments","events_url":"https://api.github.com/repos/itkasumy/Blog/issues/50/events","html_url":"https://github.com/itkasumy/Blog/issues/50","id":305458162,"number":50,"title":" ES6系列之Promise.all()方法","user":{"login":"itkasumy","id":24458297,"avatar_url":"https://avatars0.githubusercontent.com/u/24458297?v=4","gravatar_id":"","url":"https://api.github.com/users/itkasumy","html_url":"https://github.com/itkasumy","followers_url":"https://api.github.com/users/itkasumy/followers","following_url":"https://api.github.com/users/itkasumy/following{/other_user}","gists_url":"https://api.github.com/users/itkasumy/gists{/gist_id}","starred_url":"https://api.github.com/users/itkasumy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itkasumy/subscriptions","organizations_url":"https://api.github.com/users/itkasumy/orgs","repos_url":"https://api.github.com/users/itkasumy/repos","events_url":"https://api.github.com/users/itkasumy/events{/privacy}","received_events_url":"https://api.github.com/users/itkasumy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-15T08:36:41Z","updated_at":"2018-03-15T08:36:41Z","closed_at":null,"author_association":"OWNER","body":"Promise.all方法用于将多个Promise实例，包装成一个新的Promise实例。\r\n\r\n```js\r\nvar p = Promise.all([p1,p2,p3]);\r\n```\r\n\r\n上面代码中，Promise.all方法接受一个数组作为参数，p1、p2、p3都是Promise对象的实例。（Promise.all方法的参数不一定是数组，但是必须具有iterator接口，且返回的每个成员都是Promise实例。）\r\n\r\np的状态由p1、p2、p3决定，分成两种情况。\r\n\r\n- 只有p1、p2、p3的状态都变成fulfilled，p的状态才会变成fulfilled，此时p1、p2、p3的返回值组成一个数组，传递给p的回调函数。\r\n- 只要p1、p2、p3之中有一个被rejected，p的状态就变成rejected，此时第一个被reject的实例的返回值，会传递给p的回调函数。\r\n\r\n下面是一个具体的例子。\r\n\r\n```js\r\n// 生成一个Promise对象的数组\r\nvar promises = [2, 3, 5, 7, 11, 13].map(function(id){\r\n  return getJSON(\"/post/\" + id + \".json\");\r\n});\r\n \r\nPromise.all(promises).then(function(posts) {\r\n  // ...\r\n}).catch(function(reason){\r\n  // ...\r\n});\r\n```"}}
{"actor":{"display_login":"itkasumy"}}