{"id":352032,"date":"2024-05-20T22:00:42","date_gmt":"2024-05-20T22:00:42","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=352032"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=352032","title":{"rendered":"<span>2.0 \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c. Future<\/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><strong>Future<\/strong> &#8212; \u042d\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u0432\u044b\u0434\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041e\u043d\u0430 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0434\u043b\u044f:<\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0441\u0435\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0438 \u0434\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u00a0Future \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f Future&lt;T>. \u0422\u0438\u043f void \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u00a0Future \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u0430\u043a\u043e\u0439 \u043b\u0438\u0431\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<blockquote>\n<p>\u0418\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<\/blockquote>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 future \u043d\u0435 \u0432\u044b\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u043e \u0442\u0438\u043f future \u0440\u0430\u0432\u0435\u043d Future&lt;void>.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439: \u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435 \u0438\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0431\u0443\u0434\u0443\u0449\u0435\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0442\u0430\u0432\u0438\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f future \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f, future \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u043e\u0439.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/h3>\n<pre><code>void main() {   final myFuture = Future(() {     print('\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 \u0444\u044c\u044e\u0447\u0430');     return 400;   });    print('main() \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f.'); }  \/\/Console \/\/main() \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f. \/\/\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 \u0444\u044c\u044e\u0447\u0430<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0442\u044b \u0432\u0438\u0434\u0438\u0448\u044c, \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0441\u044c main \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f Future \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f.<\/p>\n<h2>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Future<\/h2>\n<h3>THEN \u0438 DELAYED<\/h3>\n<p>\u041f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Future \u043e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435. \u041d\u043e \u043a\u0430\u043a \u0436\u0435 \u043f\u043e\u0439\u043c\u0430\u0442\u044c \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 Future \u0443\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0438 \u043f\u0435\u0440\u0435\u0448\u0435\u043b \u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435? \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 Future \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d <strong>\u043c\u0435\u0442\u043e\u0434 then<\/strong>.\u00a0<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 Future. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0438\u0437 Future \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 Future.delayed \u0441\u043e\u0437\u0434\u0430\u0435\u043c future \u0441 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439 5 \u0441\u0435\u043a \u0438 \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u0430\u0442\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Future&lt;String> :<\/p>\n<pre><code>Future&lt;String> future = Future.delayed(      Duration(seconds: 5),      () {         print(\"\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 Future\");         return \"\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\";      });<\/code><\/pre>\n<p>\u0410 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043c <strong>then, <\/strong>\u0442\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u043d\u0438\u0435 \u0438\u0437 \u0444\u044c\u044e\u0447\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u043e\u0441\u044c \u0432 then:<\/p>\n<pre><code>future.then((value){     print(\"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435: $value\"); });<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/205\/812\/b89\/205812b89dfd36109469ba5025d3836a.png\" width=\"664\" height=\"195\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/205\/812\/b89\/205812b89dfd36109469ba5025d3836a.png\"\/><\/figure>\n<blockquote>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c void, \u0430 \u043d\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u043c\u0435\u0441\u0442\u043e value \u0432 then \u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0447\u0435\u0440\u043a(_).<\/p>\n<\/blockquote>\n<h4>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0438\u0437 then.<\/h4>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e34\/78b\/a71\/e3478ba71e68515d86ca95add3cc9752.png\" alt=\"\u0426\u0435\u043f\u043e\u0447\u043a\u0430 then\" title=\"\u0426\u0435\u043f\u043e\u0447\u043a\u0430 then\" width=\"735\" height=\"311\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e34\/78b\/a71\/e3478ba71e68515d86ca95add3cc9752.png\"\/><\/p>\n<div><figcaption>\u0426\u0435\u043f\u043e\u0447\u043a\u0430 then<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/940\/d1a\/e93\/940d1ae931eb2a3c5122f4c93aca75bd.png\" alt=\"\u041a\u043e\u043d\u0441\u043e\u043b\u044c\" title=\"\u041a\u043e\u043d\u0441\u043e\u043b\u044c\" width=\"635\" height=\"88\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/940\/d1a\/e93\/940d1ae931eb2a3c5122f4c93aca75bd.png\"\/><\/p>\n<div><figcaption>\u041a\u043e\u043d\u0441\u043e\u043b\u044c<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e then \u0432 \u0434\u0440\u0443\u0433\u043e\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a1f\/7ae\/080\/a1f7ae0808c0535cf5bbb9e48ca17efe.png\" alt=\"\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e return \u0432 then\" title=\"\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e return \u0432 then\" width=\"814\" height=\"166\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a1f\/7ae\/080\/a1f7ae0808c0535cf5bbb9e48ca17efe.png\"\/><\/p>\n<div><figcaption>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e return \u0432 then<\/figcaption><\/div>\n<\/figure>\n<h2>\u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a: \u043a\u0430\u043a \u043f\u043e\u0439\u043c\u0430\u0442\u044c \u043a\u043e\u0442\u0430?  <\/h2>\n<p><strong>then()<\/strong> \u0438 <strong>catchError()<\/strong> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 Future, \u0438 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0433\u0440\u0443\u0431\u044b\u0439 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u0431\u043b\u043e\u043a\u043e\u0432 try-catch.<\/p>\n<p>\u041d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u043d\u0443\u0442\u0440\u0438<strong> myFunc() <\/strong>\u0438\u043b\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 <strong>then(), catchError() <\/strong>\u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0435\u0435.<\/p>\n<p>\u0410 \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b<strong> catchError()\u00a0<\/strong> \u0438 <strong>onError \u0432\u043c\u0435\u0441\u0442\u0435 <\/strong>\u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/848\/4c0\/bb3\/8484c0bb3892545cc4512c2ebd7963e1.png\" alt=\"\u0442\u0443\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437 future \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0 onError, \u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437 then catchError()  \" title=\"\u0442\u0443\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437 future \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0 onError, \u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437 then catchError()  \" width=\"1231\" height=\"236\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/848\/4c0\/bb3\/8484c0bb3892545cc4512c2ebd7963e1.png\"\/><\/p>\n<div><figcaption><strong>\u0442\u0443\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437 future \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0 onError, \u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437 then catchError()<\/strong>  <\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p><strong>\u0426\u0438\u0442\u0430\u0442\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438:<\/strong><\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a: \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435 \u0432\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u0435\u0441\u043a\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0434\u043b\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 then().<\/p>\n<\/blockquote>\n<p>\u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u044d\u0442\u043e <strong>Future.sync():<\/strong><\/p>\n<p><strong>Future.sync()<\/strong> \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0430\u0448 \u043a\u043e\u0434 \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u043c \u043a \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u044b\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c. \u0415\u0441\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043c\u0435\u0441\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0442\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p><strong>Future.sync()<\/strong> \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <em>\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e<\/em> \u0443\u0442\u0435\u0447\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0438\u0437 \u0432\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b: <a href=\"https:\/\/dart.dev\/guides\/libraries\/futures-error-handling\" rel=\"noopener noreferrer nofollow\">https:\/\/dart.dev\/guides\/libraries\/futures-error-handling<\/a><\/p>\n<blockquote>\n<p>\u0415\u0441\u0442\u044c \u0441\u043f\u043e\u0440\u044b \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u043b\u0438  Future.value \u0438 Future.sync. \u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0447\u0442\u043e \u0434\u0430 \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u043d\u0435\u0442 \u0442\u0430\u043a. \u041f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u044d\u0442\u043e:<\/p>\n<p><a href=\"https:\/\/pmatatias.medium.com\/flutter-future-future-sync-future-microtask-future-value-etc-3f46aeae1210\" rel=\"noopener noreferrer nofollow\">https:\/\/pmatatias.medium.com\/flutter-future-future-sync-future-microtask-future-value-etc-3f46aeae1210<\/a><\/p>\n<p>\u0430 \u0442\u0430\u043a \u0436\u0435 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/dart-lang\/sdk\/issues\/44751\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/dart-lang\/sdk\/issues\/44751<\/a><\/p>\n<\/blockquote>\n<h3>Future.error<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u0437 \u0444\u044c\u044e\u0447\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>Future.error<\/p>\n<p><code>return Future.error('Error');<\/code><\/p>\n<h2>Future.microtask  <\/h2>\n<p>\u0414\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0441\u043e\u0431\u043e \u0432\u0430\u0436\u043d\u044b\u0445 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<pre><code>void main() {   print('future');   Future(() => print('future 1'));   Future(() => print('future 2'));   print('microtask');   \/\/ Microtasks will be executed before futures.   Future.microtask(() => print('microtask 1'));   Future.microtask(() => print('microtask 2')); <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b21\/c5c\/9b7\/b21c5c9b7ce7c7d5f803547f765c35fb.png\" alt=\"\u041a\u043e\u043d\u0441\u043e\u043b\u044c\" title=\"\u041a\u043e\u043d\u0441\u043e\u043b\u044c\" width=\"174\" height=\"201\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b21\/c5c\/9b7\/b21c5c9b7ce7c7d5f803547f765c35fb.png\"\/><\/p>\n<div><figcaption>\u041a\u043e\u043d\u0441\u043e\u043b\u044c<\/figcaption><\/div>\n<\/figure>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432 DartPad <a href=\"https:\/\/dartpad.dev\/49bde0c1ed780decc902f3d4d06d8f0c\" rel=\"noopener noreferrer nofollow\">https:\/\/dartpad.dev\/49bde0c1ed780decc902f3d4d06d8f0c<\/a>.<\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e microtask \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u043f\u0440\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c: <a href=\"https:\/\/pmatatias.medium.com\/flutter-future-future-sync-future-microtask-future-value-etc-3f46aeae1210\" rel=\"noopener noreferrer nofollow\">https:\/\/pmatatias.medium.com\/flutter-future-future-sync-future-microtask-future-value-etc-3f46aeae1210<\/a><\/p>\n<h3>FutureOr class<\/h3>\n<p>\u0422\u0438\u043f <strong>FutureOr&lt;int><\/strong> \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u00ab\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432\u00bb \u0442\u0438\u043f\u043e\u0432 <strong>int<\/strong> \u0438 <strong>Future&lt;int><\/strong>.<\/p>\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0430\u043c \u043e\u043d \u043d\u0443\u0436\u0435\u043d? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u00a0\u043c\u0435\u0442\u043e\u0434 <code>Future&lt;String> fetch();<\/code><\/p>\n<p>\u041c\u044b \u043e\u0431\u044f\u0437\u0430\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0430 \u043d\u0430\u043c \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p><code>FutureOr&lt;String> fetch();<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0442\u0438\u043f Future&lt;String> \u0438 String.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e. <\/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\/754268\/\"> https:\/\/habr.com\/ru\/articles\/754268\/<\/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><strong>Future<\/strong> &#8212; \u042d\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u0432\u044b\u0434\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041e\u043d\u0430 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0434\u043b\u044f:<\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0441\u0435\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0438 \u0434\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u00a0Future \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f Future&lt;T>. \u0422\u0438\u043f void \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u00a0Future \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u0430\u043a\u043e\u0439 \u043b\u0438\u0431\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<blockquote>\n<p>\u0418\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<\/blockquote>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 future \u043d\u0435 \u0432\u044b\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u043e \u0442\u0438\u043f future \u0440\u0430\u0432\u0435\u043d Future&lt;void>.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439: \u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435 \u0438\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0431\u0443\u0434\u0443\u0449\u0435\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0442\u0430\u0432\u0438\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f future \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f, future \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u043e\u0439.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/h3>\n<pre><code>void main() {   final myFuture = Future(() {     print('\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 \u0444\u044c\u044e\u0447\u0430');     return 400;   });    print('main() \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f.'); }  \/\/Console \/\/main() \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f. \/\/\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 \u0444\u044c\u044e\u0447\u0430<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0442\u044b \u0432\u0438\u0434\u0438\u0448\u044c, \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0441\u044c main \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f Future \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f.<\/p>\n<h2>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Future<\/h2>\n<h3>THEN \u0438 DELAYED<\/h3>\n<p>\u041f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Future \u043e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435. \u041d\u043e \u043a\u0430\u043a \u0436\u0435 \u043f\u043e\u0439\u043c\u0430\u0442\u044c \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 Future \u0443\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0438 \u043f\u0435\u0440\u0435\u0448\u0435\u043b \u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435? \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 Future \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d <strong>\u043c\u0435\u0442\u043e\u0434 then<\/strong>.\u00a0<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 Future. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0438\u0437 Future \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 Future.delayed \u0441\u043e\u0437\u0434\u0430\u0435\u043c future \u0441 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439 5 \u0441\u0435\u043a \u0438 \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u0430\u0442\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Future&lt;String> :<\/p>\n<pre><code>Future&lt;String> future = Future.delayed(      Duration(seconds: 5),      () {         print(\"\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 Future\");         return \"\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\";      });<\/code><\/pre>\n<p>\u0410 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043c <strong>then, <\/strong>\u0442\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u043d\u0438\u0435 \u0438\u0437 \u0444\u044c\u044e\u0447\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u043e\u0441\u044c \u0432 then:<\/p>\n<pre><code>future.then((value){     print(\"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435: $value\"); });<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<blockquote>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c void, \u0430 \u043d\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u043c\u0435\u0441\u0442\u043e value \u0432 then \u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0447\u0435\u0440\u043a(_).<\/p>\n<\/blockquote>\n<h4>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0438\u0437 then.<\/h4>\n<figure class=\"full-width\">\n<div><figcaption>\u0426\u0435\u043f\u043e\u0447\u043a\u0430 then<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\">\n<div><figcaption>\u041a\u043e\u043d\u0441\u043e\u043b\u044c<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e then \u0432 \u0434\u0440\u0443\u0433\u043e\u0439.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e return \u0432 then<\/figcaption><\/div>\n<\/figure>\n<h2>\u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a: \u043a\u0430\u043a \u043f\u043e\u0439\u043c\u0430\u0442\u044c \u043a\u043e\u0442\u0430?  <\/h2>\n<p><strong>then()<\/strong> \u0438 <strong>catchError()<\/strong> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 Future, \u0438 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0433\u0440\u0443\u0431\u044b\u0439 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u0431\u043b\u043e\u043a\u043e\u0432 try-catch.<\/p>\n<p>\u041d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u043d\u0443\u0442\u0440\u0438<strong> myFunc() <\/strong>\u0438\u043b\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 <strong>then(), catchError() <\/strong>\u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0435\u0435.<\/p>\n<p>\u0410 \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b<strong> catchError()\u00a0<\/strong> \u0438 <strong>onError \u0432\u043c\u0435\u0441\u0442\u0435 <\/strong>\u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<figure class=\"full-width\">\n<div><figcaption><strong>\u0442\u0443\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437 future \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0 onError, \u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437 then catchError()<\/strong>  <\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p><strong>\u0426\u0438\u0442\u0430\u0442\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438:<\/strong><\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a: \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435 \u0432\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u0435\u0441\u043a\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0434\u043b\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 then().<\/p>\n<\/blockquote>\n<p>\u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u044d\u0442\u043e <strong>Future.sync():<\/strong><\/p>\n<p><strong>Future.sync()<\/strong> \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0430\u0448 \u043a\u043e\u0434 \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u043c \u043a \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u044b\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c. \u0415\u0441\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043c\u0435\u0441\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0442\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p><strong>Future.sync()<\/strong> \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <em>\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e<\/em> \u0443\u0442\u0435\u0447\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0438\u0437 \u0432\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b: <a href=\"https:\/\/dart.dev\/guides\/libraries\/futures-error-handling\" rel=\"noopener noreferrer nofollow\">https:\/\/dart.dev\/guides\/libraries\/futures-error-handling<\/a><\/p>\n<blockquote>\n<p>\u0415\u0441\u0442\u044c \u0441\u043f\u043e\u0440\u044b \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u043b\u0438  Future.value \u0438 Future.sync. \u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0447\u0442\u043e \u0434\u0430 \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u043d\u0435\u0442 \u0442\u0430\u043a. \u041f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u044d\u0442\u043e:<\/p>\n<p><a href=\"https:\/\/pmatatias.medium.com\/flutter-future-future-sync-future-microtask-future-value-etc-3f46aeae1210\" rel=\"noopener noreferrer nofollow\">https:\/\/pmatatias.medium.com\/flutter-future-future-sync-future-microtask-future-value-etc-3f46aeae1210<\/a><\/p>\n<p>\u0430 \u0442\u0430\u043a \u0436\u0435 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/dart-lang\/sdk\/issues\/44751\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/dart-lang\/sdk\/issues\/44751<\/a><\/p>\n<\/blockquote>\n<h3>Future.error<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u0437 \u0444\u044c\u044e\u0447\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>Future.error<\/p>\n<p><code>return Future.error('Error');<\/code><\/p>\n<h2>Future.microtask  <\/h2>\n<p>\u0414\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0441\u043e\u0431\u043e \u0432\u0430\u0436\u043d\u044b\u0445 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<pre><code>void main() {   print('future');   Future(() => print('future 1'));   Future(() => print('future 2'));   print('microtask');   \/\/ Microtasks will be executed before futures.   Future.microtask(() => print('microtask 1'));   Future.microtask(() => print('microtask 2')); <\/code><\/pre>\n<figure class=\"\">\n<div><figcaption>\u041a\u043e\u043d\u0441\u043e\u043b\u044c<\/figcaption><\/div>\n<\/figure>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432 DartPad <a href=\"https:\/\/dartpad.dev\/49bde0c1ed780decc902f3d4d06d8f0c\" rel=\"noopener noreferrer nofollow\">https:\/\/dartpad.dev\/49bde0c1ed780decc902f3d4d06d8f0c<\/a>.<\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e microtask \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u043f\u0440\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c: <a href=\"https:\/\/pmatatias.medium.com\/flutter-future-future-sync-future-microtask-future-value-etc-3f46aeae1210\" rel=\"noopener noreferrer nofollow\">https:\/\/pmatatias.medium.com\/flutter-future-future-sync-future-microtask-future-value-etc-3f46aeae1210<\/a><\/p>\n<h3>FutureOr class<\/h3>\n<p>\u0422\u0438\u043f <strong>FutureOr&lt;int><\/strong> \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u00ab\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432\u00bb \u0442\u0438\u043f\u043e\u0432 <strong>int<\/strong> \u0438 <strong>Future&lt;int><\/strong>.<\/p>\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0430\u043c \u043e\u043d \u043d\u0443\u0436\u0435\u043d? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u00a0\u043c\u0435\u0442\u043e\u0434 <code>Future&lt;String> fetch();<\/code><\/p>\n<p>\u041c\u044b \u043e\u0431\u044f\u0437\u0430\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0430 \u043d\u0430\u043c \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p><code>FutureOr&lt;String> fetch();<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0442\u0438\u043f Future&lt;String> \u0438 String.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e. <\/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\/754268\/\"> https:\/\/habr.com\/ru\/articles\/754268\/<\/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-352032","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/352032","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=352032"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/352032\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}