{"id":352021,"date":"2024-05-20T22:00:31","date_gmt":"2024-05-20T22:00:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=352021"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=352021","title":{"rendered":"<span>3.0 \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c. async \u0438 await<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0432 Dart 1.9 <strong>async<\/strong> \u0438 <strong>await<\/strong> \u044d\u0442\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u043d\u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0443\u0431\u0440\u0430\u0442\u044c \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430.<\/p>\n<ul>\n<li>\n<p><strong>async<\/strong>: \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043b\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0435\u0435 \u043a\u0430\u043a \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e.<\/p>\n<p><code>void main() async { \u00b7\u00b7\u00b7 }<\/code><\/p>\n<\/li>\n<li>\n<p><strong>async \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/strong>: \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u0430\u044f async \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c. \u0422\u043e\u0433\u0434\u0430 \u0432 \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c await.<\/p>\n<p><code>Future&lt;String> main() async { \u00b7\u00b7\u00b7 }<\/code><\/p>\n<\/li>\n<li>\n<p><strong>await<\/strong>: \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e <em>\u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u044d\u0442\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438<\/em>.\u00a0<strong>await<\/strong> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 <strong>async<\/strong> \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p><code>print(await GetPosts());<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c \u0437\u0430\u0447\u0435\u043c \u0436\u0435 \u043d\u0430\u043c \u0436\u0434\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"dart\"> call() {   var emp = getEmploye();   return '\u043d\u0430 \u0437\u0432\u043e\u043d\u043e\u043a \u043e\u0442\u0432\u0435\u0442\u0438\u043b: $emp'; }  Future&lt;String> getEmploye() =>     Future.delayed(       const Duration(seconds: 2),       () => '\u0434\u044f\u0434\u044f \u041f\u0435\u0442\u044f',     );  void main() {   print('\u0417\u0432\u043e\u043d\u044e \u0432 \u043e\u0442\u0434\u0435\u043b...');   print(call()); }<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/51c\/839\/aa9\/51c839aa9403e5b2a3a799822c456462.png\" alt=\"\u041a\u043e\u043d\u0441\u043e\u043b\u044c\" title=\"\u041a\u043e\u043d\u0441\u043e\u043b\u044c\" width=\"624\" height=\"88\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/51c\/839\/aa9\/51c839aa9403e5b2a3a799822c456462.png\"\/><\/p>\n<div><figcaption>\u041a\u043e\u043d\u0441\u043e\u043b\u044c<\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e emp \u043c\u044b \u0432\u0438\u0434\u0438\u043c  <code>Instance of '_Future&lt;String>' \\<\/code> . Future \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0431\u0435\u0449\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 \u0435\u0433\u043e. <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443 \u043d\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430:<\/p>\n<ol>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 call, main \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 <code>async.<\/code><\/p>\n<\/li>\n<li>\n<p>&#171;\u0414\u043e\u0436\u0434\u0435\u043c\u0441\u044f&#187; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438  <code>getEmploye()<\/code><\/p>\n<\/li>\n<li>\n<p>&#171;\u0414\u043e\u0436\u0434\u0435\u043c\u0441\u044f&#187; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438  <code>call() \u0432 main<\/code><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"dart\"> call() async{   var emp = await getEmploye();   return '\u043d\u0430 \u0437\u0432\u043e\u043d\u043e\u043a \u043e\u0442\u0432\u0435\u0442\u0438\u043b: $emp'; }  Future&lt;String> getEmploye() =>     Future.delayed(       const Duration(seconds: 2),       () => '\u0434\u044f\u0434\u044f \u041f\u0435\u0442\u044f',     );  void main() async{   print('\u0417\u0432\u043e\u043d\u044e \u0432 \u043e\u0442\u0434\u0435\u043b...');   print(await call()); }<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e63\/276\/5ce\/e632765ce8c8d78bde2e1bebdff60c5c.png\" alt=\"\u041a\u043e\u043d\u0441\u043e\u043b\u044c\" title=\"\u041a\u043e\u043d\u0441\u043e\u043b\u044c\" width=\"506\" height=\"82\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e63\/276\/5ce\/e632765ce8c8d78bde2e1bebdff60c5c.png\"\/><\/p>\n<div><figcaption>\u041a\u043e\u043d\u0441\u043e\u043b\u044c<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043e Dart 1.9, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u00a0<code>then()<\/code>\u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430. \u042d\u0442\u043e\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430\u00a0\u0444\u044c\u044e\u0447\u0430\u00a0\u0437\u0430\u0432\u0435\u0440\u0448\u0430\u043b\u0430\u0441\u044c:<\/p>\n<pre><code class=\"dart\">  void main () {   print('start');   Message();   print(\"\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 main\"); }   void Message() {     print(\"\u041d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Message\");     Future&lt;String> messageFuture = getMessage();     messageFuture.then((val){         print(\"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435: $val\");     }).then((val){print('end');});     print(\"\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Message\"); }   Future&lt;String> getMessage() {   return Future.delayed(Duration(seconds: 3), () => \"\u0414\u043e\u0431\u0440\u043e\u0435 \u0443\u0442\u0440\u043e\"); } <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/489\/a58\/73d\/489a5873d4bcd56b29ab2e56d3844190.png\" width=\"515\" height=\"195\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/489\/a58\/73d\/489a5873d4bcd56b29ab2e56d3844190.png\"\/><\/figure>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 <strong>then \u0432\u043c\u0435\u0441\u0442\u043e async await<\/strong>, \u0443\u0436\u0435 \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u0435 \u0441 <strong>async await<\/strong>: <\/p>\n<pre><code class=\"dart\">Future&lt;void>  Message() async {   print('start');     print(\"\u041d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438  Message\");     String message = await getMessage();     print(\"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435: $message\");     print(\"\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438  Message\");   print('end'); }   Future&lt;String> getMessage() {   return Future.delayed(Duration(seconds: 3), () => \"\u0414\u043e\u0431\u0440\u043e\u0435 \u0443\u0442\u0440\u043e\"); }   void main () {    Message();   print(\"\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 main\"); }<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c0a\/e75\/28b\/c0ae7528baf347c4081977f117e02df5.png\" width=\"515\" height=\"195\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c0a\/e75\/28b\/c0ae7528baf347c4081977f117e02df5.png\"\/><\/figure>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043b\u0435\u0433\u0447\u0435 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c. \u0418 \u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043d\u044f\u043b\u0438 \u0447\u0442\u043e \u043d\u0430\u043c \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043d\u0443\u0436\u043d\u044b async await.<\/p>\n<h2>\u041b\u043e\u0432\u0438\u043c \u043a\u0440\u0430\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u0442\u0430<\/h2>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h4>\n<pre><code> call() async{  try {   var emp = await getEmploye();   return '\u043d\u0430 \u0437\u0432\u043e\u043d\u043e\u043a \u043e\u0442\u0432\u0435\u0442\u0438\u043b: $emp';    } catch (e) {     \/\/ handle error...   } }<\/code><\/pre>\n<p>E\u0441\u043b\u0438 \u0432<code>try<\/code>\u00a0\u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438\u00a0<code>catch<\/code>.  <\/p>\n<h2>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0440\u0435\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0442\u044b \u043c\u043e\u0436\u0435\u0448\u044c \u043f\u043e\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f:<\/p>\n<p><a href=\"https:\/\/dart.dev\/codelabs\/async-await\" rel=\"noopener noreferrer nofollow\">https:\/\/dart.dev\/codelabs\/async-await<\/a><\/p>\n<p>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044e:<\/p>\n<p><a href=\"https:\/\/metanit.com\/dart\/tutorial\/7.3.php\" rel=\"noopener noreferrer nofollow\">https:\/\/metanit.com\/dart\/tutorial\/7.3.php<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/5AxWC49ZMzs\" rel=\"noopener noreferrer nofollow\">https:\/\/youtu.be\/5AxWC49ZMzs<\/a>  \u043d\u0430 \u0430\u043d\u0433\u043b \u043e\u0442 Flutter Team \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438, \u0445\u043e\u0442\u044f \u0431\u044b \u0441 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u043e\u043c \u0438\u043b\u0438 \u0441\u0443\u0431\u0442\u0438\u0442\u0440\u0430\u043c\u0438, \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0442\u0435\u043c\u044b, \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0432 \u044d\u0442\u043e\u043c \u0432\u0438\u0434\u0435\u043e.<\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/442282\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/articles\/442282\/<\/a><\/p>\n<p>\u041a\u0430\u043a \u0442\u0435\u0431\u0435 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f? \u041f\u0438\u0448\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c\u0441\u044f:)<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/754280\/\"> https:\/\/habr.com\/ru\/articles\/754280\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0432 Dart 1.9 <strong>async<\/strong> \u0438 <strong>await<\/strong> \u044d\u0442\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u043d\u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0443\u0431\u0440\u0430\u0442\u044c \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430.<\/p>\n<ul>\n<li>\n<p><strong>async<\/strong>: \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043b\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0435\u0435 \u043a\u0430\u043a \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e.<\/p>\n<p><code>void main() async { \u00b7\u00b7\u00b7 }<\/code><\/p>\n<\/li>\n<li>\n<p><strong>async \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/strong>: \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u0430\u044f async \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c. \u0422\u043e\u0433\u0434\u0430 \u0432 \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c await.<\/p>\n<p><code>Future&lt;String> main() async { \u00b7\u00b7\u00b7 }<\/code><\/p>\n<\/li>\n<li>\n<p><strong>await<\/strong>: \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e <em>\u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u044d\u0442\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438<\/em>.\u00a0<strong>await<\/strong> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 <strong>async<\/strong> \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p><code>print(await GetPosts());<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c \u0437\u0430\u0447\u0435\u043c \u0436\u0435 \u043d\u0430\u043c \u0436\u0434\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"dart\"> call() {   var emp = getEmploye();   return '\u043d\u0430 \u0437\u0432\u043e\u043d\u043e\u043a \u043e\u0442\u0432\u0435\u0442\u0438\u043b: $emp'; }  Future&lt;String> getEmploye() =>     Future.delayed(       const Duration(seconds: 2),       () => '\u0434\u044f\u0434\u044f \u041f\u0435\u0442\u044f',     );  void main() {   print('\u0417\u0432\u043e\u043d\u044e \u0432 \u043e\u0442\u0434\u0435\u043b...');   print(call()); }<\/code><\/pre>\n<figure class=\"full-width\">\n<div><figcaption>\u041a\u043e\u043d\u0441\u043e\u043b\u044c<\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e emp \u043c\u044b \u0432\u0438\u0434\u0438\u043c  <code>Instance of '_Future&lt;String>' \\<\/code> . Future \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0431\u0435\u0449\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 \u0435\u0433\u043e. <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443 \u043d\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430:<\/p>\n<ol>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 call, main \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 <code>async.<\/code><\/p>\n<\/li>\n<li>\n<p>&#171;\u0414\u043e\u0436\u0434\u0435\u043c\u0441\u044f&#187; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438  <code>getEmploye()<\/code><\/p>\n<\/li>\n<li>\n<p>&#171;\u0414\u043e\u0436\u0434\u0435\u043c\u0441\u044f&#187; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438  <code>call() \u0432 main<\/code><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"dart\"> call() async{   var emp = await getEmploye();   return '\u043d\u0430 \u0437\u0432\u043e\u043d\u043e\u043a \u043e\u0442\u0432\u0435\u0442\u0438\u043b: $emp'; }  Future&lt;String> getEmploye() =>     Future.delayed(       const Duration(seconds: 2),       () => '\u0434\u044f\u0434\u044f \u041f\u0435\u0442\u044f',     );  void main() async{   print('\u0417\u0432\u043e\u043d\u044e \u0432 \u043e\u0442\u0434\u0435\u043b...');   print(await call()); }<\/code><\/pre>\n<figure class=\"\">\n<div><figcaption>\u041a\u043e\u043d\u0441\u043e\u043b\u044c<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043e Dart 1.9, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u00a0<code>then()<\/code>\u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430. \u042d\u0442\u043e\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430\u00a0\u0444\u044c\u044e\u0447\u0430\u00a0\u0437\u0430\u0432\u0435\u0440\u0448\u0430\u043b\u0430\u0441\u044c:<\/p>\n<pre><code class=\"dart\">  void main () {   print('start');   Message();   print(\"\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 main\"); }   void Message() {     print(\"\u041d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Message\");     Future&lt;String> messageFuture = getMessage();     messageFuture.then((val){         print(\"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435: $val\");     }).then((val){print('end');});     print(\"\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Message\"); }   Future&lt;String> getMessage() {   return Future.delayed(Duration(seconds: 3), () => \"\u0414\u043e\u0431\u0440\u043e\u0435 \u0443\u0442\u0440\u043e\"); } <\/code><\/pre>\n<figure class=\"\"><\/figure>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 <strong>then \u0432\u043c\u0435\u0441\u0442\u043e async await<\/strong>, \u0443\u0436\u0435 \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u0435 \u0441 <strong>async await<\/strong>: <\/p>\n<pre><code class=\"dart\">Future&lt;void>  Message() async {   print('start');     print(\"\u041d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438  Message\");     String message = await getMessage();     print(\"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435: $message\");     print(\"\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438  Message\");   print('end'); }   Future&lt;String> getMessage() {   return Future.delayed(Duration(seconds: 3), () => \"\u0414\u043e\u0431\u0440\u043e\u0435 \u0443\u0442\u0440\u043e\"); }   void main () {    Message();   print(\"\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 main\"); }<\/code><\/pre>\n<figure class=\"\"><\/figure>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043b\u0435\u0433\u0447\u0435 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c. \u0418 \u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043d\u044f\u043b\u0438 \u0447\u0442\u043e \u043d\u0430\u043c \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043d\u0443\u0436\u043d\u044b async await.<\/p>\n<h2>\u041b\u043e\u0432\u0438\u043c \u043a\u0440\u0430\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u0442\u0430<\/h2>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h4>\n<pre><code> call() async{  try {   var emp = await getEmploye();   return '\u043d\u0430 \u0437\u0432\u043e\u043d\u043e\u043a \u043e\u0442\u0432\u0435\u0442\u0438\u043b: $emp';    } catch (e) {     \/\/ handle error...   } }<\/code><\/pre>\n<p>E\u0441\u043b\u0438 \u0432<code>try<\/code>\u00a0\u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438\u00a0<code>catch<\/code>.  <\/p>\n<h2>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0440\u0435\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0442\u044b \u043c\u043e\u0436\u0435\u0448\u044c \u043f\u043e\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f:<\/p>\n<p><a href=\"https:\/\/dart.dev\/codelabs\/async-await\" rel=\"noopener noreferrer nofollow\">https:\/\/dart.dev\/codelabs\/async-await<\/a><\/p>\n<p>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044e:<\/p>\n<p><a href=\"https:\/\/metanit.com\/dart\/tutorial\/7.3.php\" rel=\"noopener noreferrer nofollow\">https:\/\/metanit.com\/dart\/tutorial\/7.3.php<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/5AxWC49ZMzs\" rel=\"noopener noreferrer nofollow\">https:\/\/youtu.be\/5AxWC49ZMzs<\/a>  \u043d\u0430 \u0430\u043d\u0433\u043b \u043e\u0442 Flutter Team \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438, \u0445\u043e\u0442\u044f \u0431\u044b \u0441 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u043e\u043c \u0438\u043b\u0438 \u0441\u0443\u0431\u0442\u0438\u0442\u0440\u0430\u043c\u0438, \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0442\u0435\u043c\u044b, \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0432 \u044d\u0442\u043e\u043c \u0432\u0438\u0434\u0435\u043e.<\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/442282\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/articles\/442282\/<\/a><\/p>\n<p>\u041a\u0430\u043a \u0442\u0435\u0431\u0435 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f? \u041f\u0438\u0448\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c\u0441\u044f:)<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/754280\/\"> https:\/\/habr.com\/ru\/articles\/754280\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-352021","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/352021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=352021"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/352021\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}