{"id":1906,"date":"2019-02-22T14:26:32","date_gmt":"2019-02-22T13:26:32","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=1906"},"modified":"2019-03-06T10:09:37","modified_gmt":"2019-03-06T09:09:37","slug":"assign-result-array-from-promise-all","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/assign-result-array-from-promise-all\/","title":{"rendered":"Assign result array from Promise.all"},"content":{"rendered":"\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const getTasks = () => Promise.delay(500).then(() => ['task1']);\nconst getUsers = () => Promise.delay(400).then(() => ['user1', 'user2']);\nconst getInvoices = () => Promise.delay(300).then(() => ['invoice4']);\nconst getColors = () => Promise.delay(200).then(() => ['color1', 'color2']);\n\nconst run = async () => {\n  const [\n      tasks, \n      users, \n      invoices, \n      colors\n      ] = await Promise.all([\n          getTasks(),\n          getUsers(),\n          getInvoices(),\n          getColors()\n      ]);              \n   return { tasks, users, invoices, colors };\n};\n      \nconst t0 = performance.now();\nrun().then((result) => {\n\tdocument.write(`&lt;pre>${JSON.stringify(result, null, 4)}&lt;\/pre>`);\n    const t1 = performance.now();\n\tconsole.log(`Call to doSomething took ${(t1 - t0)} ms.`);\n});\n   \n<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1906","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=1906"}],"version-history":[{"count":2,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1906\/revisions"}],"predecessor-version":[{"id":1967,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1906\/revisions\/1967"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=1906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=1906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=1906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}