{"id":35959,"date":"2019-10-31T22:08:45","date_gmt":"2019-10-31T19:08:45","guid":{"rendered":"https:\/\/prohoster.info\/blog\/razbiraem-async-await-v-javascript-na-primerah\/"},"modified":"2019-10-31T22:08:45","modified_gmt":"2019-10-31T19:08:45","slug":"razbiraem-async-await-v-javascript-na-primerah","status":"publish","type":"post","link":"https:\/\/prohoster.info\/de\/blog\/novosti-interneta\/razbiraem-async-await-v-javascript-na-primerah","title":{"rendered":"Async\/Await in JavaScript: Ein \u00dcberblick durch Beispiele","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p>\n\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 Async\/Await \u0432 JavaScript. \u0412 \u0446\u0435\u043b\u043e\u043c, Async\/Await \u2014 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0414\u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0438\u0441\u0430\u043b\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u043e\u0432 \u0438 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432. \u0410\u0432\u0442\u043e\u0440 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 Async\/Await, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b.<br \/>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<blockquote><p><b>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c:<\/b> <i>\u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u00ab\u0425\u0430\u0431\u0440\u0430\u00bb \u2014 \u0441\u043a\u0438\u0434\u043a\u0430 10 000 \u0440\u0443\u0431\u043b\u0435\u0439 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u0443\u0440\u0441 Skillbox \u043f\u043e \u043f\u0440\u043e\u043c\u043e\u043a\u043e\u0434\u0443 \u00ab\u0425\u0430\u0431\u0440\u00bb.<\/i><\/p>\n<p><b>Skillbox \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442:<\/b> \u041e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441 <noindex><a rel=\"nofollow\" href=\"https:\/\/skillbox.ru\/java\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=JAVDEV&amp;utm_content=articles&amp;utm_term=async\">\u00abJava-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u00bb<\/a><\/noindex>.<\/p><\/blockquote>\n<p><\/p>\n<h3>Callback <\/h3>\n<p>\nCallback \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0442\u043b\u043e\u0436\u0435\u043d \u043d\u0430 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0420\u0430\u043d\u044c\u0448\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0432 \u0442\u0435\u0445 \u0443\u0447\u0430\u0441\u0442\u043a\u0430\u0445 \u043a\u043e\u0434\u0430, \u0433\u0434\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435 \u043c\u043e\u0433 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0441\u0440\u0430\u0437\u0443.<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 Node.js:<\/p>\n<pre><code class=\"javascript\">fs.readFile(__filename, 'utf-8', (err, data) =&gt; {\n  if (err) {\n    throw err;\n  }\n  console.log(data);\n});<\/code><\/pre>\n<p>\n\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0432 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0435\u0431\u0435 \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0411\u0414 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f Arfat, \u043d\u0443\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u043b\u0435 profile_img_url \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 someserver.com.<br \/>\n\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u0438\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 PNG \u0432 JPEG. \u0415\u0441\u043b\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0448\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u044c\u043c\u043e. \u0414\u0430\u043b\u0435\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0438 \u0437\u0430\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b transformations.log \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0434\u0430\u0442\u044b.<\/p>\n<p>\n\u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0430\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e }) \u0432 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430. \u042d\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Callback Hell \u0438\u043b\u0438 Pyramid of Doom.<\/p>\n<p>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b:<\/p>\n<ul>\n<li>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u043b\u043e\u0436\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c.<\/li>\n<li>\u0412 \u043d\u0435\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0447\u0442\u043e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0443\u0445\u0443\u0434\u0448\u0435\u043d\u0438\u044e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0434\u0430.<\/li>\n<\/ul>\n<p>\n\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0432 JavaScript \u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043f\u0440\u043e\u043c\u0438\u0441\u044b. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0433\u043b\u0443\u0431\u043e\u043a\u0443\u044e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u043e\u0432 \u0441\u043b\u043e\u0432\u043e\u043c .then.<\/p>\n<p>\n\u041f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u043c \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432 \u0441\u0442\u0430\u043b\u043e \u0442\u043e, \u0447\u0442\u043e \u0441 \u043d\u0438\u043c\u0438 \u043a\u043e\u0434 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435, \u043f\u0440\u0438\u0447\u0435\u043c \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437, \u0430 \u043d\u0435 \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0443 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432 \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<ul>\n<li>\u041d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e .then.<\/li>\n<li>\u0412\u043c\u0435\u0441\u0442\u043e try\/catch \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f .catch \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0441\u0435\u0445 \u043e\u0448\u0438\u0431\u043e\u043a.<\/li>\n<li>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u043c\u0438\u0441\u0430\u043c\u0438 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u043e\u0431\u043d\u0430, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043e\u043d\u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u044e\u0442 \u043a\u043e\u0434.<\/li>\n<\/ul>\n<p>\n\u0412\u043e\u0442 \u0437\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0446\u0438\u043a\u043b for, \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0438\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0447\u0438\u0441\u0435\u043b \u043e\u0442 0 \u0434\u043e 10 \u0441\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c (0\u2013n \u0441\u0435\u043a\u0443\u043d\u0434). \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u043e\u043c\u0438\u0441\u044b, \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0446\u0438\u043a\u043b \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0447\u0438\u0441\u043b\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0442 0 \u0434\u043e 10. \u0422\u0430\u043a, \u0435\u0441\u043b\u0438 \u0432\u044b\u0432\u043e\u0434 \u043d\u0443\u043b\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 6 \u0441\u0435\u043a\u0443\u043d\u0434, \u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u2014 2 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0432\u0435\u0434\u0435\u043d \u043d\u043e\u043b\u044c, \u0430 \u043f\u043e\u0442\u043e\u043c \u0443\u0436\u0435 \u043d\u0430\u0447\u043d\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u0447\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u044b.<\/p>\n<p>\u0418 \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Async\/Await \u043b\u0438\u0431\u043e .sort. \u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u2014 \u0432 \u043a\u043e\u043d\u0446\u0435.<\/p>\n<h3>Async-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h3>\n<p>\n \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 async-\u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 ES2017 (ES8) \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u043e \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0440\u043e\u043c\u0438\u0441\u0430\u043c\u0438. \u041e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e async-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u00ab\u043f\u043e\u0432\u0435\u0440\u0445\u00bb \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432. \u042d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438. Async-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u043a\u0430\u043a \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u043a\u043e\u0434\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0440\u043e\u043c\u0438\u0441\u044b.<\/p>\n<p>Async\/Await \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0437\u043d\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432 \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432 Async\/Await.<\/p>\n<p><b>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441<\/b><\/p>\n<p>\u0412 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043e\u043d \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432: async \u0438 await. \u041f\u0435\u0440\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 await. \u0412 \u043b\u044e\u0431\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<pre><code class=\"javascript\">\/\/ With function declaration\n \nasync function myFn() {\n  \/\/ await ...\n}\n \n\/\/ With arrow function\n \nconst myFn = async () =&gt; {\n  \/\/ await ...\n}\n \nfunction myFn() {\n  \/\/ await fn(); (Syntax Error since no async)\n}\n <\/code><\/pre>\n<p>\nAsync \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u043c\u0435\u0436\u0434\u0443 \u0437\u043d\u0430\u043a\u043e\u043c \u00ab=\u00bb \u0438 \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438.<\/p>\n<p>\u042d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043b\u0438\u0431\u043e \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<pre><code class=\"javascript\">\/\/ As an object's method\n \nconst obj = {\n  async getName() {\n    return fetch('https:\/\/www.example.com');\n  }\n}\n \n\/\/ In a class\n \nclass Obj {\n  async getResource() {\n    return fetch('https:\/\/www.example.com');\n  }\n}<\/code><\/pre>\n<p>\nNB! \u0421\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0433\u0435\u0442\u0442\u0435\u0440\u044b\/\u0441\u0435\u0442\u0442\u0435\u0440\u044b \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p><b>\u0421\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/b><\/p>\n<p>Async-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0435\u0441\u0442\u044c \u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0422\u0430\u043a, async-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043f\u0440\u043e\u043c\u0438\u0441\u044b:<\/p>\n<pre><code class=\"javascript\">async function fn() {\n  return 'hello';\n}\nfn().then(console.log)\n\/\/ hello<\/code><\/pre>\n<p>\n\u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, fn \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 hello. \u041d\u0443 \u0430 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043e\u0431\u0435\u0440\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u043c\u0438\u0441 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430.<\/p>\n<p>\u0412\u043e\u0442 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0431\u0435\u0437 Async:<\/p>\n<pre><code class=\"javascript\">function fn() {\n  return Promise.resolve('hello');\n}\n \nfn().then(console.log);\n\/\/ hello<\/code><\/pre>\n<p>\n\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u043c\u0438\u0441\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u00ab\u0432\u0440\u0443\u0447\u043d\u0443\u044e\u00bb. \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0431\u0435\u0440\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u043c\u0438\u0441.<\/p>\n<p>\u0412 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432, async-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043e\u0431\u0435\u0440\u0442\u044b\u0432\u0430\u044f \u0435\u0433\u043e \u0432 \u043f\u0440\u043e\u043c\u0438\u0441. \u0412 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u043e\u043c\u0438\u0441\u0430, \u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u0440\u043e\u043c\u0438\u0441\u0435.<\/p>\n<pre><code class=\"javascript\">const p = Promise.resolve('hello')\np instanceof Promise;\n\/\/ true\n \nPromise.resolve(p) === p;\n\/\/ true\n <\/code><\/pre>\n<p>\n\u041d\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430?<\/p>\n<pre><code class=\"javascript\">async function foo() {\n  throw Error('bar');\n}\n \nfoo().catch(console.log);<\/code><\/pre>\n<p>\n\u0415\u0441\u043b\u0438 \u043e\u043d\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430, foo() \u0432\u0435\u0440\u043d\u0435\u0442 \u043f\u0440\u043e\u043c\u0438\u0441 \u0441 \u0440\u0435\u0434\u0436\u0435\u043a\u0442\u043e\u043c. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0432\u043c\u0435\u0441\u0442\u043e Promise.resolve \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f Promise.reject, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>Async-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0430\u044e\u0442 \u043f\u0440\u043e\u043c\u0438\u0441, \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c await .<\/p>\n<p>Await \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0422\u0430\u043a, \u0435\u0441\u043b\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u043c, async-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u043c\u0438\u0441\u0430. \u0412 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u043c, \u043e\u043d\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u043c\u0438\u0441 \u0447\u0435\u0440\u0435\u0437 Promise.resolve \u0438 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"javascript\">\/\/ utility function to cause delay\n\/\/ and get random value\n \nconst delayAndGetRandom = (ms) =&gt; {\n  return new Promise(resolve =&gt; setTimeout(\n    () =&gt; {\n      const val = Math.trunc(Math.random() * 100);\n      resolve(val);\n    }, ms\n  ));\n};\n \nasync function fn() {\n  const a = await 9;\n  const b = await delayAndGetRandom(1000);\n  const c = await 5;\n  await delayAndGetRandom(1000);\n \n  return a + b * c;\n}\n \n\/\/ Execute fn\nfn().then(console.log);<\/code><\/pre>\n<p>\n\u0410 \u0432\u043e\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 fn-\u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<ul>\n<li>\u041f\u043e\u0441\u043b\u0435 \u0435\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0437 const a = await 9; \u0432 const a = await Promise.resolve(9);.<\/li>\n<li>\u041f\u043e\u0441\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Await \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u043a\u0430 \u0430 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u044d\u0442\u043e 9).<\/li>\n<li>delayAndGetRandom(1000) \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 fn-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0441\u0430\u043c\u0430 (\u043f\u043e\u0441\u043b\u0435 1 \u0441\u0435\u043a\u0443\u043d\u0434\u044b). \u042d\u0442\u043e \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 fn-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443.<\/li>\n<li>delayAndGetRandom(1000) \u0447\u0435\u0440\u0435\u0437 resolve \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 b.<\/li>\n<li>\u041d\u0443 \u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u0441\u043b\u0443\u0447\u0430\u044e \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0430. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c delayAndGetRandom(1000) \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/li>\n<li>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435 a + b * c. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0436\u0435 \u043e\u0431\u0435\u0440\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u043c\u0438\u0441 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Promise.resolve \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439.<\/li>\n<\/ul>\n<p>\n\u042d\u0442\u0438 \u043f\u0430\u0443\u0437\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0432 ES6, \u043d\u043e \u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c <noindex><a rel=\"nofollow\" href=\"https:\/\/codeburst.io\/understanding-generators-in-es6-javascript-with-examples-6728834016d5\">\u0441\u0432\u043e\u0438 \u043f\u0440\u0438\u0447\u0438\u043d\u044b<\/a><\/noindex>.<\/p>\n<h3>\u0420\u0435\u0448\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443<\/h3>\n<p>\n\u041d\u0443 \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u044b\u043b\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432\u044b\u0448\u0435.<\/p>\n<p>\n\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 finishMyTask \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Await \u0434\u043b\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0442\u0430\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043a\u0430\u043a queryDatabase, sendEmail, logTaskInFile \u0438 \u0434\u0440\u0443\u0433\u0438\u0445. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0442\u0435\u043c, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043f\u0440\u043e\u043c\u0438\u0441\u044b, \u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u0435\u0440\u0441\u0438\u044f \u0441 Async\/Await \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0432\u0441\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u043e\u0432 \u0438 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0432\u0440\u043e\u0434\u0435 .then\/.catch.<\/p>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0447\u0438\u0441\u0435\u043b, \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430.<\/p>\n<pre><code class=\"javascript\">const wait = (i, ms) =&gt; new Promise(resolve =&gt; setTimeout(() =&gt; resolve(i), ms));\n \n\/\/ Implementation One (Using for-loop)\nconst printNumbers = () =&gt; new Promise((resolve) =&gt; {\n  let pr = Promise.resolve(0);\n  for (let i = 1; i &lt;= 10; i += 1) {\n    pr = pr.then((val) =&gt; {\n      console.log(val);\n      return wait(i, Math.random() * 1000);\n    });\n  }\n  resolve(pr);\n});\n \n\/\/ Implementation Two (Using Recursion)\n \nconst printNumbersRecursive = () =&gt; {\n  return Promise.resolve(0).then(function processNextPromise(i) {\n \n    if (i === 10) {\n      return undefined;\n    }\n \n    return wait(i, Math.random() * 1000).then((val) =&gt; {\n      console.log(val);\n      return processNextPromise(i + 1);\n    });\n  });\n};<\/code><\/pre>\n<p>\n\u0410 \u0432\u043e\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c async-\u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<pre><code class=\"javascript\">async function printNumbersUsingAsync() {\n  for (let i = 0; i &lt; 10; i++) {\n    await wait(i, Math.random() * 1000);\n    console.log(i);\n  }\n}<\/code><\/pre>\n<p>\n<b>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/b><\/p>\n<p>\u041d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u0431\u0435\u0440\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 rejected \u043f\u0440\u043e\u043c\u0438\u0441. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432 async-\u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e try\/catch \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<pre><code class=\"javascript\">async function canRejectOrReturn() {\n  \/\/ wait one second\n  await new Promise(res =&gt; setTimeout(res, 1000));\n \n\/\/ Reject with ~50% probability\n  if (Math.random() &gt; 0.5) {\n    throw new Error('Sorry, number too big.')\n  }\n \nreturn 'perfect number';\n}<\/code><\/pre>\n<p>\ncanRejectOrReturn() \u2014 \u044d\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043b\u0438\u0431\u043e \u0443\u0434\u0430\u0447\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f (\u201cperfect number\u201d), \u043b\u0438\u0431\u043e \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 (\u201cSorry, number too big\u201d).<\/p>\n<pre><code class=\"javascript\">async function foo() {\n  try {\n    await canRejectOrReturn();\n  } catch (e) {\n    return 'error caught';\n  }\n}<\/code><\/pre>\n<p>\n\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 canRejectOrReturn, \u0442\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0432\u043b\u0435\u0447\u0435\u0442 \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0430 catch. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f foo \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u0441 undefined (\u043a\u043e\u0433\u0434\u0430 \u0432 \u0431\u043b\u043e\u043a\u0435 try \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f), \u043b\u0438\u0431\u043e \u0441 error caught. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0443 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 try\/catch \u0437\u0430\u0439\u043c\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0441\u0430\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 foo.<\/p>\n<p>\u0412\u043e\u0442 \u0435\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"javascript\">async function foo() {\n  try {\n    return canRejectOrReturn();\n  } catch (e) {\n    return 'error caught';\n  }\n}<\/code><\/pre>\n<p>\n\u0421\u0442\u043e\u0438\u0442 \u0443\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0437 foo \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f canRejectOrReturn. Foo \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0431\u043e perfect number, \u043b\u0438\u0431\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430 Error (\u201cSorry, number too big\u201d). \u0411\u043b\u043e\u043a catch \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e foo \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u043c\u0438\u0441, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 canRejectOrReturn. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 foo \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f canRejectOrReturn. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"javascript\">try {\n    const promise = canRejectOrReturn();\n    return promise;\n}<\/code><\/pre>\n<p>\n\u0410 \u0432\u043e\u0442 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435 await \u0438 return:<\/p>\n<pre><code class=\"javascript\">async function foo() {\n  try {\n    return await canRejectOrReturn();\n  } catch (e) {\n    return 'error caught';\n  }\n}<\/code><\/pre>\n<p>\n\u0412 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 foo \u0443\u0434\u0430\u0447\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u0441 perfect number, \u0442\u0430\u043a \u0438 \u0441 error caught. \u0417\u0434\u0435\u0441\u044c \u043e\u0442\u043a\u0430\u0437\u043e\u0432 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u041d\u043e foo \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0441 canRejectOrReturn, \u0430 \u043d\u0435 \u0441 undefined. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c, \u0443\u0431\u0440\u0430\u0432 \u0441\u0442\u0440\u043e\u043a\u0443 return await canRejectOrReturn():<\/p>\n<pre><code class=\"javascript\">try {\n    const value = await canRejectOrReturn();\n    return value;\n}\n\/\/ \u2026<\/code><\/pre>\n<p><\/p>\n<h3>\u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438<\/h3>\n<p>\n\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Async\/Await \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c.<\/p>\n<p><b>\u0417\u0430\u0431\u044b\u0442\u044b\u0439 await<\/b><\/p>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u2014 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u043c \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e await:<\/p>\n<pre><code class=\"javascript\">async function foo() {\n  try {\n    canRejectOrReturn();\n  } catch (e) {\n    return 'caught';\n  }\n}<\/code><\/pre>\n<p>\n\u0412 \u043a\u043e\u0434\u0435, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043d\u0435\u0442 \u043d\u0438 await, \u043d\u0438 return. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 foo \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0441 undefined \u0431\u0435\u0437 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0432 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443. \u041d\u043e \u043f\u0440\u043e\u043c\u0438\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043e\u043d \u0432\u044b\u0434\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u0438\u043b\u0438 \u0440\u0435\u0434\u0436\u0435\u043a\u0442, \u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f UnhandledPromiseRejectionWarning.<\/p>\n<p><b>Async-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445<\/b><\/p>\n<p>Async-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 .map \u0438\u043b\u0438 .filter \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u043e\u0432. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e fetchPublicReposCount(username), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u043d\u0430 GitHub \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u044c\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b. \u0412\u043e\u0442 \u043a\u043e\u0434 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<pre><code class=\"javascript\">const url = 'https:\/\/api.github.com\/users';\n \n\/\/ Utility fn to fetch repo counts\nconst fetchPublicReposCount = async (username) =&gt; {\n  const response = await fetch(`${url}\/${username}`);\n  const json = await response.json();\n  return json['public_repos'];\n}<\/code><\/pre>\n<p>\n\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u044b ArfatSalman, octocat, norvig. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c:<\/p>\n<pre><code class=\"javascript\">const users = [\n  'ArfatSalman',\n  'octocat',\n  'norvig'\n];\n \nconst counts = users.map(async username =&gt; {\n  const count = await fetchPublicReposCount(username);\n  return count;\n});<\/code><\/pre>\n<p>\n\u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 Await \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 .map. \u0417\u0434\u0435\u0441\u044c counts \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432, \u043d\u0443 \u0430 .map \u2014 \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p><b>\u0427\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 await<\/b><\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"javascript\">async function fetchAllCounts(users) {\n  const counts = [];\n  for (let i = 0; i &lt; users.length; i++) {\n    const username = users[i];\n    const count = await fetchPublicReposCount(username);\n    counts.push(count);\n  }\n  return counts;\n}<\/code><\/pre>\n<p>\n\u0417\u0434\u0435\u0441\u044c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e count \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u043e \u0440\u0435\u043f\u043e, \u0437\u0430\u0442\u0435\u043c \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 counts. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043a\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u043a\u0430 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0435 \u043f\u0440\u0438\u0434\u0443\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0432\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u0435\u0434\u0438\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c.<\/p>\n<p>\u0415\u0441\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0443\u0445\u043e\u0434\u0438\u0442 \u043e\u043a\u043e\u043b\u043e 300 \u043c\u0441, \u0442\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u044d\u0442\u043e \u0443\u0436\u0435 \u0441\u0435\u043a\u0443\u043d\u0434\u0430, \u0437\u0430\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0447\u0438\u0441\u043b\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u041d\u043e \u0440\u0430\u0437 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0435\u043f\u043e \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 .map \u0438 Promise.all:<\/p>\n<pre><code class=\"javascript\">async function fetchAllCounts(users) {\n  const promises = users.map(async username =&gt; {\n    const count = await fetchPublicReposCount(username);\n    return count;\n  });\n  return Promise.all(promises);\n}<\/code><\/pre>\n<p>\nPromise.all \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u043c\u0438\u0441\u0430. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0438\u043b\u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0440\u0435\u0434\u0436\u0435\u043a\u0442\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f. \u041c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a, \u0447\u0442\u043e \u0432\u0441\u0435 \u043e\u043d\u0438 \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u044f\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u2014 \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c p-map.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\nAsync-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u041d\u0443 \u0430 \u0434\u043b\u044f \u0430\u0434\u0430\u043f\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f async-\u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u0442\u043e\u0438\u0442 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/tc39\/proposal-async-iteration\" rel=\"nofollow noopener noreferrer\">Async Iterators<\/a><\/noindex>. JavaScript-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c.<\/p>\n<blockquote><p><b>Skillbox \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442:<\/b><\/p>\n<ul>\n<li>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0443\u0440\u0441 <noindex><a rel=\"nofollow\" href=\"https:\/\/skillbox.ru\/agima\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=AGIMA&amp;utm_content=articles&amp;utm_term=async\">\u00ab\u041c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a PRO\u00bb<\/a><\/noindex>.<\/li>\n<li>\u041f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441 <noindex><a rel=\"nofollow\" href=\"https:\/\/skillbox.ru\/python-data\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=PTNANA&amp;utm_content=articles&amp;utm_term=async\">\u00ab\u0410\u043d\u0430\u043b\u0438\u0442\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 Python\u00bb<\/a><\/noindex>.<\/li>\n<li>\u0414\u0432\u0443\u0445\u043b\u0435\u0442\u043d\u0438\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0443\u0440\u0441 <noindex><a rel=\"nofollow\" href=\"https:\/\/iamwebdev.skillbox.ru\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=WEBDEVPRO&amp;utm_content=articles&amp;utm_term=async\">\u00ab\u042f \u2014 \u0412\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a PRO\u00bb<\/a><\/noindex>.<\/li>\n<\/ul>\n<\/blockquote>\n<p>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/skillbox\/blog\/458950\/\">habr.com<\/a><\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 Async\/Await \u0432 JavaScript. \u0412 \u0446\u0435\u043b\u043e\u043c, Async\/Await \u2014 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0414\u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0438\u0441\u0430\u043b\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u043e\u0432 \u0438 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432. \u0410\u0432\u0442\u043e\u0440 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 Async\/Await, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b. \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c: \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u00ab\u0425\u0430\u0431\u0440\u0430\u00bb \u2014 \u0441\u043a\u0438\u0434\u043a\u0430 10 000 \u0440\u0443\u0431\u043b\u0435\u0439 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u0443\u0440\u0441 Skillbox \u043f\u043e [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[702],"tags":[],"class_list":["post-35959","post","type-post","status-publish","format-standard","hentry","category-novosti-interneta"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 Async\/Await \u0432 JavaScript. \u0412 \u0446\u0435\u043b\u043e\u043c, Async\/Await \u2014 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0414\u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0438\u0441\u0430\u043b\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u043e\u0432 \u0438 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432. \u0410\u0432\u0442\u043e\u0440 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 Async\/Await, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b. \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c: \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u00ab\u0425\u0430\u0431\u0440\u0430\u00bb \u2014 \u0441\u043a\u0438\u0434\u043a\u0430 10 000 \u0440\u0443\u0431\u043b\u0435\u0439 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u0443\u0440\u0441 Skillbox \u043f\u043e\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/de\/blog\/novosti-interneta\/razbiraem-async-await-v-javascript-na-primerah\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"de_DE\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c Async\/Await \u0432 JavaScript \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 Async\/Await \u0432 JavaScript. \u0412 \u0446\u0435\u043b\u043e\u043c, Async\/Await \u2014 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0414\u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0438\u0441\u0430\u043b\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u043e\u0432 \u0438 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432. \u0410\u0432\u0442\u043e\u0440 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 Async\/Await, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b. \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c: \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u00ab\u0425\u0430\u0431\u0440\u0430\u00bb \u2014 \u0441\u043a\u0438\u0434\u043a\u0430 10 000 \u0440\u0443\u0431\u043b\u0435\u0439 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u0443\u0440\u0441 Skillbox \u043f\u043e\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/de\/blog\/novosti-interneta\/razbiraem-async-await-v-javascript-na-primerah\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-10-31T19:08:45+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-10-31T19:08:45+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Async\/Await in JavaScript: Beispiele und Erkl\u00e4rungen | ProHoster","description":"Der Artikelautor erkl\u00e4rt anhand von Beispielen, wie Async\/Await in JavaScript funktioniert. Insgesamt ist Async\/Await eine praktische Methode, um asynchr\u00f6nen Code zu schreiben. Bis zu dieser M\u00f6glichkeit wurde solcher Code mit Callbacks und Promises geschrieben. Der Autor des Originalartikels hebt die Vorteile von Async\/Await hervor und analysiert verschiedene Beispiele. Wir erinnern alle \u201eHabr\u201c-Leser daran: 10.000 Rubel Rabatt beim Einschreiben in jeden Skillbox-Kurs.","canonical_url":"https:\/\/prohoster.info\/de\/blog\/novosti-interneta\/razbiraem-async-await-v-javascript-na-primerah","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"de_DE","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c Async\/Await \u0432 JavaScript \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 | ProHoster","og:description":"\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 Async\/Await \u0432 JavaScript. \u0412 \u0446\u0435\u043b\u043e\u043c, Async\/Await \u2014 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0414\u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0438\u0441\u0430\u043b\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u043e\u0432 \u0438 \u043f\u0440\u043e\u043c\u0438\u0441\u043e\u0432. \u0410\u0432\u0442\u043e\u0440 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 Async\/Await, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b. \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c: \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u00ab\u0425\u0430\u0431\u0440\u0430\u00bb \u2014 \u0441\u043a\u0438\u0434\u043a\u0430 10 000 \u0440\u0443\u0431\u043b\u0435\u0439 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u0443\u0440\u0441 Skillbox \u043f\u043e","og:url":"https:\/\/prohoster.info\/de\/blog\/novosti-interneta\/razbiraem-async-await-v-javascript-na-primerah","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-10-31T19:08:45+00:00","article:modified_time":"2019-10-31T19:08:45+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"35959","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-22 01:26:19","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 15:48:48","updated":"2026-01-22 01:26:19"},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/posts\/35959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/comments?post=35959"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/posts\/35959\/revisions"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/media?parent=35959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/categories?post=35959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/tags?post=35959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}