{"id":221111,"date":"2014-04-28T10:52:03","date_gmt":"2014-04-28T06:52:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=221111"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=221111","title":{"rendered":"<span class=\"post_title\">\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 promise \u0432 angular.js<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/3b4\/885\/554\/3b48855549271fca37b6a5ead123662e.png\" alt=\"image\" align=\"right\"\/>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f angular.js \u0442\u0440\u0443\u0434\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 $q (\u043e\u043d \u0436\u0435 promise\/deferred), \u0432\u0435\u0434\u044c \u043e\u043d \u043b\u0435\u0436\u0438\u0442 \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u0441\u0435\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430. Deferred \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438 \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434. \u041d\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043c\u043e\u0449\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u043d\u0430\u0442\u044c \u043e \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430. <br \/>  \u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0437\u043d\u0430\u043b\u0438.<br \/>  <a name=\"habracut\"><\/a>   <\/p>\n<hr\/>\n<h4>1. then \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 promise<\/h4>\n<p>  \u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"javascript\">function asyncFunction() {     var deferred = $q.defer();     doSomethingAsync().then(function(res) {       res = asyncManipulate(res);     deferred.resolve(res);   }, function(err) {     deferred.reject(err);   });    return deferred.promise;  } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u043e\u0435 \u043e\u0431\u0435\u0449\u0430\u043d\u0438\u0435 <code>$q.defer()<\/code>. \u0410\u0432\u0442\u043e\u0440 \u043a\u043e\u0434\u0430 \u044f\u0432\u043d\u043e \u043d\u0435 \u0437\u043d\u0430\u043b \u0447\u0442\u043e then \u0438\u0442\u0430\u043a \u0432\u0435\u0440\u043d\u0435\u0442 promise. \u0427\u0442\u043e\u0431\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u043e\u0434, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u0440\u043d\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 then:<\/p>\n<pre><code class=\"javascript\">function asyncFunction() {    return doSomethingAsync().then(function(res) {       return asyncManipulate(res);   });  } <\/code><\/pre>\n<h4>2. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 promise \u00ab\u043d\u0435 \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f\u00bb<\/h4>\n<p>  \u0421\u043d\u043e\u0432\u0430 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"javascript\">function asyncFunction() {     return doSomethingAsync().then(function(res) {       return asyncManipulate(res);   }, function(err) {     return $q.reject(err);   }); } <\/code><\/pre>\n<p>  \u041b\u044e\u0431\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>doSomethingAsync<\/code> \u0431\u0443\u0434\u044c \u0442\u043e resolve \u0438\u043b\u0438 reject \u0431\u0443\u0434\u0435\u0442 \u00ab\u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0442\u044c\u00bb \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442 \u0441\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a (\u0435\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442). \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u0432\u0435\u0434\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0438\u0441\u0447\u0435\u0437\u043d\u0435\u0442, \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0434\u0430\u043b\u044c\u0448\u0435. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 reject), \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f:<\/p>\n<pre><code class=\"javascript\">function asyncFunction() {     return doSomethingAsync().then(function(res) {       return asyncManipulate(res);   }); } <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 resolve \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u0443\u0447\u0430\u0439 reject:<\/p>\n<pre><code class=\"javascript\">function asyncFunction() {     return doSomethingAsync().then(null, function(err) {       return errorHandler(err);   }); } <\/code><\/pre>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440:<\/p>\n<pre><code class=\"javascript\">function asyncFunction() {     return doSomethingAsync().catch(function(err) {       return errorHandler(err);   }); } <\/code><\/pre>\n<h4>3. \u041f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 reject \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u043d\u0443\u0432 $q.reject()<\/h4>\n<p>  \u041a\u043e\u0434:<\/p>\n<pre><code class=\"javascript\">asyncFunction().then(function (res) {   \/\/ some code   return res; }, function (res) {   \/\/ some code }).then(function (res) {   console.log('in resolve'); }, function (res) {   console.log('in reject'); }); <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>asyncFunction<\/code> \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c &#8216;in resolve&#8217;. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0432 reject \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u2014 \u0432\u0435\u0440\u043d\u0443\u0442\u044c $q.reject(). \u0412 \u043b\u044e\u0431\u044b\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d resolve \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 &#8216;in reject&#8217; \u0435\u0441\u043b\u0438 <code>asyncFunction<\/code> \u0432\u0435\u0440\u043d\u0435\u0442 reject:<\/p>\n<pre><code class=\"javascript\">asyncFunction().then(function (res) {   \/\/ some code   return res; }, function (res) {   \/\/ some code   return $q.reject(res); }).then(function (res) {   console.log('in resolve'); }, function (res) {   console.log('in reject'); }); <\/code><\/pre>\n<h4>4. finally \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 promise<\/h4>\n<pre><code class=\"javascript\">asyncFunction().then(function (res) {   importantFunction();   return res; }, function (err) {   importantFunction();   return $q.reject(err); }).then(function (res) {   \/\/ some resolve code }, function (err) {   \/\/ some reject code }) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u0434 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 promise \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 finally \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u0434\u0430. \u0422\u0430\u043a \u0436\u0435 \u0431\u043b\u043e\u043a finally \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0442\u0438\u043f promise \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430. \u0423\u043b\u0443\u0447\u0448\u0430\u0435\u043c:<\/p>\n<pre><code class=\"javascript\">asyncFunction().finally(function () {   importantFunction(); }).then(function (res) {   \/\/ some resolve code }, function (err) {   \/\/ some reject code }) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 finally \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u0435\u0440\u043d\u0435\u0442 $q.reject(), \u0442\u043e \u0442\u043e\u0433\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d reject \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u0421\u043f\u043e\u0441\u043e\u0431\u0430 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c resolve \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0435\u0442. <\/p>\n<h4>5. $q.all \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e<\/h4>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">loadSomeInfo().then(function(something) {     loadAnotherInfo().then(function(another) {     doSomethingOnThem(something, another);   }); }); <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u0438 <code>doSomethingOnThem<\/code> \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u0435\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>loadSomeInfo<\/code> \u0438 <code>loadAnotherInfo<\/code>. \u0418 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043a\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u044b, \u0432\u0430\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u0447\u0442\u043e\u0431\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>doSomethingOnThem<\/code> \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0442 \u043e\u0431\u0435\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0417\u043d\u0430\u0447\u0438\u0442 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e. \u041d\u043e \u0430\u0432\u0442\u043e\u0440 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u044f\u0432\u043d\u043e \u043d\u0435 \u0437\u043d\u0430\u043b \u043f\u0440\u043e $q.all \u043c\u0435\u0442\u043e\u0434. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c:<\/p>\n<pre><code class=\"javascript\">$q.all([loadSomeInfo(), loadAnotherInfo()]).then(function (results) {   doSomethingOnThem(results[0], results[1]); }); <\/code><\/pre>\n<p>  $q.all \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u044b \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e. \u041e\u0431\u0435\u0449\u0430\u043d\u0438\u0435, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 $q.all, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u0441\u044f. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <code>results<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u0441\u0435\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<br \/>  \u0422\u0430\u043a\u043e\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u0435\u0442\u043e\u0434 $q.all \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<h4>6. $q.when \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0441\u0435 \u0432 promise<\/h4>\n<p>  \u0411\u044b\u0432\u0430\u044e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439. \u0418 \u0442\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u043d\u0430\u0434 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432 \u043a\u043e\u0434\u0435:<\/p>\n<pre><code class=\"javascript\">var promise; if (isAsync){   promise = asynkFunction(); } else {   var localPromise = $q.defer();    promise = localPromise.promise;   localPromise.resolve(42); }  promise.then(function (res) {   \/\/ some code }); <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043b\u043e\u0445\u043e\u0433\u043e. \u041d\u043e \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0447\u0438\u0449\u0435: <\/p>\n<pre><code class=\"javascript\">$q.when(isAsync? asynkFunction(): 42).then(function (res) {   \/\/ some code }); <\/code><\/pre>\n<p>  $q.when \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u043f\u0440\u043e\u043a\u0441\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043b\u0438\u0431\u043e promise \u043b\u0438\u0431\u043e \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 promise.<\/p>\n<h4>7. \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 promise<\/h4>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"javascript\">function asynkFunction(){   return $timeout(function meAsynk(){     throw new Error('error in meAsynk');       }, 1); }  try{   asynkFunction(); } catch(err){   errorHandler(err); } <\/code><\/pre>\n<p>  \u0412\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443? try\/catch \u0431\u043b\u043e\u043a \u043f\u043e\u0439\u043c\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>asynkFunction<\/code>. \u041d\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a <code>$timeout<\/code> \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442 \u0441\u0432\u043e\u044e \u043a\u0430\u043b\u0431\u044d\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>meAsynk<\/code>, \u0432\u0441\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043c \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0435 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (application\u2019s uncaught exception handler). \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430\u0448 catch \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0443\u0437\u043d\u0430\u0435\u0442.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 try\/catch \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u043e. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0442\u0430\u043a\u0438\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445? \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0430\u043b\u0431\u0435\u043a \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a. \u0412 $q \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f reject \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.<br \/>  \u041f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0435\u043c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u043e\u0448\u0438\u0431\u043a\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0441\u0430\u0445\u0430\u0440 <code>catch<\/code>):<\/p>\n<pre><code class=\"javascript\">function asynkFunction(){   return $timeout(function meAsynk(){     throw new Error('error in meAsynk');       }, 1); }  asynkFunction().catch(function (err) {   errorHandler(err); }); <\/code><\/pre>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"javascript\">function asyncFunction() {       var promise = doSomethingAsync();     promise.then(function() {         return somethingAsyncAgain();     });      return promise; } <\/code><\/pre>\n<p>  \u0423 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: \u0435\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>somethingAsyncAgain <\/code> \u0432\u0435\u0440\u043d\u0435\u0442 reject (\u0430 \u043a\u0430\u043a \u043c\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u043c reject \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043a\u043e\u0433\u0434\u0430 \u043f\u0430\u0434\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438), \u0442\u043e \u043a\u043e\u0434 \u0432\u044b\u0437\u0432\u0430\u0432\u0448\u0438\u0439 \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0435 \u0443\u0437\u043d\u0430\u0435\u0442. \u041e\u0431\u0435\u0449\u0430\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e. \u041d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0431\u0435\u0449\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u043e\u0440\u0432\u0430\u043d\u043e. \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">function asyncFunction() {       return doSomethingAsync().then(function() {         return somethingAsyncAgain();     }); } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0438\u0442\u043e\u0433\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>somethingAsyncAgain<\/code>, \u0438 \u0432\u0441\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"javascript\">asynkFunction().then(     function() {     return somethingElseAsync();   },   function(err) {     errorHandler(err); }); <\/code><\/pre>\n<p>  \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u041d\u043e \u0435\u0441\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0443\u043f\u0430\u0434\u0435\u0442 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>somethingElseAsync<\/code>, \u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u043a\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b reject \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0431\u044b\u043b \u043e\u0431\u043e\u0441\u043e\u0431\u043b\u0435\u043d:<\/p>\n<pre><code class=\"javascript\">asynkFunction().then(function() {   return somethingElseAsync(); }).catch(function(err) {   errorHandler(err); }); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043b\u044e\u0431\u0430\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430.<\/p>\n<h4><b>P.S.<\/b><\/h4>\n<p>  \u0421\u0435\u0440\u0432\u0438\u0441 $q \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430 <a href=\"http:\/\/promises-aplus.github.io\/promises-spec\/\"> Promises\/A+<\/a>. \u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442.<br \/>  \u0422\u0430\u043a \u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f promise \u0432 jQuery \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430 Promises\/A+. \u0422\u0435\u043c \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u044d\u0442\u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0441 <a href=\"https:\/\/github.com\/kriskowal\/q\/wiki\/Coming-from-jQuery\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439<\/a>.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/221111\/\"> http:\/\/habrahabr.ru\/post\/221111\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/3b4\/885\/554\/3b48855549271fca37b6a5ead123662e.png\" alt=\"image\" align=\"right\"\/>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f angular.js \u0442\u0440\u0443\u0434\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 $q (\u043e\u043d \u0436\u0435 promise\/deferred), \u0432\u0435\u0434\u044c \u043e\u043d \u043b\u0435\u0436\u0438\u0442 \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u0441\u0435\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430. Deferred \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438 \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434. \u041d\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043c\u043e\u0449\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u043d\u0430\u0442\u044c \u043e \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430. <br \/>  \u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0437\u043d\u0430\u043b\u0438.  <\/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-221111","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/221111","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=221111"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/221111\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=221111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=221111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=221111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}