{"id":4848,"date":"2016-03-08T00:34:39","date_gmt":"2016-03-07T16:34:39","guid":{"rendered":"https:\/\/sdeno.com\/?p=4848"},"modified":"2017-11-22T09:27:57","modified_gmt":"2017-11-22T01:27:57","slug":"js%e5%bc%82%e6%ad%a5%e6%a8%a1%e5%9d%97%e4%bb%a5%e5%8f%8a%e5%9b%9e%e8%b0%83-async-js","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=4848","title":{"rendered":"js\u5f02\u6b65\u6a21\u5757\u4ee5\u53ca\u56de\u8c03--async.js"},"content":{"rendered":"<p>js jquery \u5f02\u6b65 \u56de\u8c03\u00a0Deferred promise \u5730\u72f1\u56de\u8c03\u00a0\u5730\u72f1 \u56de\u8c03<\/p>\n<p>\u8bf4\u5230js\u7684\u5f02\u6b65\u5c31\u4f1a\u8ba9\u6211\u60f3\u5230\u4f7f\u7528requirejs\u548cjquery\u7684$.ajax\uff0c\u548cHTML5\u7684\u5f02\u6b65\uff0c\u4e4b\u524d\u90fd\u6709\u4ecb\u7ecd\u8fc7\u53ef\u4ee5\u53c2\u9605\uff1a<\/p>\n<p>\u300a<a href=\"https:\/\/sdeno.com\/?p=4826\" target=\"_blank\" rel=\"noopener\">jquery\u5185\u7f6e\u5f02\u6b65\u529f\u80fd\u7b80\u5355\u4f7f\u7528<\/a>\u300b \u300a<a href=\"https:\/\/sdeno.com\/?p=4767\" target=\"_blank\" rel=\"noopener\">html5\u5f02\u6b65<\/a>\u300b \u300a<a href=\"https:\/\/sdeno.com\/?p=3854\" target=\"_blank\" rel=\"noopener\">requirejs\u6559\u7a0b<\/a>\u300b \u300a<a href=\"https:\/\/sdeno.com\/?p=3846\" target=\"_blank\" rel=\"noopener\">requirejs\u6a21\u5757\u7ba1\u7406\u63d2\u4ef6\u7b80\u5355\u4ecb\u7ecd\u53ca\u6848\u4f8b<\/a>\u300b<\/p>\n<p>&nbsp;<\/p>\n<p>IE 6+<br \/>\nOpera 15+<br \/>\nSafari 5+<br \/>\nChrome 30+<br \/>\nFirefox 3.6.28+<\/p>\n<p>&nbsp;<\/p>\n<p>async.js\u662f\u4e3anodejs\u5f00\u53d1\u51fa\u6765\u7684\u5f02\u6b65\u7f16\u7a0b\u6a21\u5757\uff0c\u4f46\u662f\u4e5f\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u7f51\u9875\u4e2d\u4f7f\u7528\uff0c\u517c\u5bb9\u6027\u53ef\u4ee5\u652f\u6301IE6\u4ee5\u4e0a\u3002<\/p>\n<p>\u5982\u679c\u8981\u5728nodejs\u4e0a\u4f7f\u7528\u5c31\u5b89\u88c5<\/p>\n<p>\u4e0b\u8f7d\uff1a<a href=\"https:\/\/sdeno.com\/wp-content\/uploads\/2016\/03\/async.rar\">async.rar<\/a><\/p>\n<pre>npm install async<\/pre>\n<pre>&lt;script src=\"async.min.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>\u4e3e\u4e24\u4e2a\u7b80\u5355\u4f8b\u5b50\uff1a<\/p>\n<pre>\u00a0\/\/\u540c\u6b65\uff0c\u53ea\u6709\u5f53\u524d\u9762\u7684\u51fd\u6570\u6267\u884c\u5b8c\u6210\u540e\uff0c\u540e\u9762\u7684\u51fd\u6570\u624d\u80fd\u6267\u884c\uff0c\u90fd\u6267\u884c\u5b8c\u6210\u540e\u624d\u56de\u8c03\u6210\u529f\u51fd\u6570\uff0c\r\n\u5982\u679c\u4e2d\u9014\u6709\u9519\u8bef\u88ab\u6fc0\u6d3b\u540e\u9762\u7684\u51fd\u6570\u4e5f\u4e0d\u4f1a\u6267\u884c\uff0c\u7acb\u9a6c\u56de\u8c03\u51fa\u9519\u8bef\u7684\u51fd\u6570\u3002\r\n\r\nasync.series([ \r\n  function (fn) {\r\n     setTimeout(function () {\r\n       $('div').css({ 'background': 'red' });\r\n       fn(null); \/\/\u5728\u540c\u6b65\u65f6\uff0c\u8bbe\u7f6enull\u8868\u793a\u6210\u529f\uff0c\u4e0b\u9762\u7684\u6b65\u9aa4\u624d\u4f1a\u6267\u884c\uff0cnull\u4ee5\u5916\u7684\u5185\u5bb9\u8868\u793a\u9519\u8bef\r\n     }, 3000);\r\n  }, function (fn) {\r\n     console.log(2);\r\n     fn(null);\r\n  }], function (err, sucess) {\r\n     if (err) {\r\n        document.title = '\u51fa\u9519\uff0c\u6ca1\u5168\u90e8\u90fd\u6267\u884c';\r\n     } else if (sucess) {\r\n        document.title = '\u6210\u529f\uff0c\u5168\u90e8\u90fd\u6267\u884c\u4e86';\r\n     } \r\n });\r\n\r\n\u4f5c\u7528\u5c31\u662f\u4e3a\u67d0\u4e2a\u51fd\u6570\u6dfb\u52a0\u56de\u8c03\u51fd\u6570\uff0c\u8fd9\u4e2a\u5176\u5b9e\u5728jquery\u4e5f\u80fd\u5b9e\u73b0\u3002<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>\/\/each \r\n\/\/\u5f02\u6b65\uff0c\u4e0d\u7ba1\u4e4b\u524d\u7684\u51fd\u6570\u6709\u6ca1\u6709\u6267\u884c\uff0c\u540e\u9762\u7684\u51fd\u6570\u4e5f\u80fd\u5148\u6267\u884c\uff0c\u90fd\u6267\u884c\u5b8c\u6210\u540e\u624d\u8fdb\u884c\u56de\u8c03\r\n\r\nvar items = [    \r\n   function (callback) {\r\n     setTimeout(function () { alert(1); callback() }, 2000);\r\n   },\r\n   function (callback) {\r\n     alert(2);\r\n     callback()\r\n   }\r\n ];\r\n\r\n\r\nasync.<span style=\"color: #ff0000;\">each<\/span>(items, function (item, callback) {\r\n    (item)(callback);\r\n  }, function () {\r\n    alert('\u90fd\u6267\u884c\u4e86');\r\n });\r\n\r\n\r\n--------------------------------------------------------------------------------------\r\n\r\n\/\/\u5f02\u6b65\uff0ceachLimit\u5f53\u4f5c\u662feach\u7684\u52a0\u5f3a\u7248\uff0c\u53ea\u662f\u6dfb\u52a0\u4e86\u4e00\u4e2alimit\u53c2\u6570\u4e5f\u5c31\u662f\u5141\u8bb8\u540c\u65f6\u6267\u884c\u51fd\u6570\u7684\u8fdb\u7a0b\u6570\u91cf\r\n\/\/\u5728\u6ca1\u6709\u51fa\u9519\u7684\u60c5\u51b5\u4e0b\uff0c\u4e0b\u9762\u7684\u4f8b\u5b50\u5f39\u51fa\u7684\u987a\u5e8f\u662f 2\uff0c3\uff0c1\uff0c5\uff0c4\r\n\/\/\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3a\u4e00\u4e2a\u5395\u6240\u67092\u4e2a\u516c\u5171\u5751\u4f4d\uff0c1\u548c2\u540c\u65f6\u8fdb\uff0c3,4,5\u540e\u9762\u7b49\u30022\u7acb\u9a6c\u5c31\u51fa\u6765\uff0c1\u8fd8\u8fdf\u8fdf\u6ca1\u51fa\u6765\uff0c\r\n\/\/2\u7684\u4f4d\u7f6e\u5c31\u8ba93\u7ed9\u7528\u4e86\uff0c3\u4e5f\u7acb\u9a6c\u51fa\u6765\uff0c\u63a5\u77404\u8fdb\u53bb\uff0c\u8fd9\u65f6\u523b4\u548c1\u540c\u65f6\u5728\u91cc\u9762\u30021\u7ec8\u4e8e\u51fa\u6765\u4e86\uff0c\r\n\/\/5\u7acb\u9a6c\u8fdb\u53bb\u4e5f\u7acb\u9a6c\u51fa\u6765\uff0c\u6700\u540e4\u4e5f\u51fa\u6765\u4e86\u3002\r\n\r\n\/\/\u67d0\u4e2a\u51fd\u6570\u4e2d\u6fc0\u6d3b\u9519\u8bef\u51fd\u6570\uff0c\u540e\u9762\u7684\u51fd\u6570\u4e0d\u4f1a\u8fd0\u884c\uff0c\u9519\u8bef\u56de\u8c03\u7acb\u9a6c\u88ab\u6267\u884c\r\n\r\n\r\nasync.<span style=\"color: #ff0000;\">eachLimit<\/span>([ \r\n   function (callback) {\r\n      setTimeout(function () {\r\n        alert(1);\r\n        callback()\r\n      }, 4000);\r\n   }, function (callback) {\r\n        alert(2);\r\n        callback()\r\n   }, function (callback) {\r\n        alert(3);\r\n        callback()\r\n   }, function (callback) {\r\n        setTimeout(function () {\r\n          alert(4);\r\n          callback()\r\n        }, 5000);\r\n    }, function (callback) {\r\n         alert(5);\r\n         callback()\r\n       }\r\n  ],2, function (item, callback) {\r\n       (item)(callback);\r\n      }, function (err) {\r\n          if (err) {\r\n              alert('\u6709\u9519\u8bef\u5230\u6b64\u4e3a\u6b62');\r\n          } else {\r\n              alert('\u90fd\u6267\u884c\u5b8c\u6210\u4e86');\r\n          }\r\n });\r\n\r\n\r\n\r\n\r\n--------------------------------------------------------------------------------\r\n\r\n\/\/eachSeries   \r\n\/\/\u548ceach\u67092\u70b9\u4e0d\u540c\uff0c\r\n\/\/1,eachSeries\u662f\u540c\u6b65\u7684\r\n\/\/2,\u4e00\u65e6\u67d0\u4e00\u4e2a\u51fd\u6570\u4e2d\u7684\u9519\u8bef\u88ab\u6fc0\u6d3b\uff0c\u6b64\u51fd\u6570\u7684\u540e\u9762\u5176\u4ed6\u51fd\u6570\u5c31\u4e0d\u4f1a\u6267\u884c\r\n\r\nasync.<span style=\"color: #ff0000;\">eachSeries<\/span>([\r\n  function (callback) {\r\n    setTimeout(function () {\r\n       alert(1);\r\n       callback()\r\n    }, 2000);\r\n  }, function (callback) {\r\n       alert(2);\r\n       callback()\r\n  }, function (callback) {\r\n       alert(3);\r\n       callback()\r\n  }\r\n ], function (item, callback) {\r\n       (item)(callback);\r\n }, function (err) {\r\n      if (err) {\r\n        alert('\u6709\u9519\u8bef\u5230\u6b64\u4e3a\u6b62');\r\n      } else {\r\n        alert('\u90fd\u6267\u884c\u5b8c\u6210\u4e86');\r\n      }\r\n });\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>\/\/ \u540c\u6b65,\u4e0a\u4e00\u4e2a\u51fd\u6570\u53ef\u4ee5\u4f20\u503c\u7ed9\u4e0b\u4e00\u4e2a\u51fd\u6570\u4f7f\u7528\uff0c\u5982\u679c\u67d0\u4e00\u4e2a\u51fd\u6570\u9519\u8bef\u6fc0\u6d3b\u540e\u9762\u7684\u51fd\u6570\u4e5f\u4e0d\u80fd\u6267\u884c\uff0c\u4e4b\u540e\u5c31\u662f\u56de\u8c03\r\n\/\/waterfall \u7684 tasks \u53c2\u6570\u53ea\u80fd\u662f\u6570\u7ec4\u7c7b\u578b\r\nasync.<span style=\"color: #ff0000;\">waterfall<\/span>([\r\n   function (callback) {\r\n      callback(null, 'one', 'two');\r\n   },\r\n   function (arg1, arg2, callback) { \/\/\u4e0a\u9762\u7684callback\u4f202\u4e2a\u53c2\u6570\uff0c\u8981\u63a5\u53d7\u7684\u8bdd\u5c31\u8bbe\u7f6e2\u4e2a\u53c2\u6570\r\n      console.log(arg1 + '--' + arg2); \/\/ one--two\r\n      callback(null, 'three','fff','4444');\r\n   },\r\n      function (arg1, arg2, arg3, callback) {\/\/\u4e0a\u9762\u7684callback\u4f203\u4e2a\u53c2\u6570\uff0c\u8981\u63a5\u53d7\u7684\u8bdd\u5c31\u8bbe\u7f6e3\u4e2a\u53c2\u6570\r\n      console.log(arg1 + '--' + arg2 + '--' + arg3); \/\/three--fff--4444\r\n      callback(null, 'done');\r\n   }\r\n ], function (err, result) {\r\n      if (err) {\r\n          alert('\u6709\u9519\u8bef' + err);\r\n      } else {\r\n          alert('\u90fd\u6267\u884c\u4e86' + result);\r\n      }\r\n });\r\n\r\n\r\n\r\n\r\n\/\/\u5982\u679c\u5e0c\u671b\u7b2c\u4e00\u4e2a\u51fd\u6570\u4e5f\u80fd\u63a5\u6536\u5230\u5176\u4ed6\u503c\u7684\u8bdd\u53ef\u4ee5\u8fd9\u4e48\u5199\r\n\r\nasync.waterfall([\r\n   async.apply(myFirstFunction, 'zero'),\r\n   mySecondFunction,\r\n   myLastFunction,\r\n ], function (err, result) {\r\n   \/\/ result now equals 'done'\r\n });\r\n\r\n\r\n function myFirstFunction(arg1, callback) {\r\n   \/\/ \u7b2c\u4e00\u4e2a\u51fd\u6570\u63a5\u6536\u5230zero\u53c2\u6570\r\n   callback(null, 'one', 'two');\r\n }\r\n function mySecondFunction(arg1, arg2, callback) {\r\n   callback(null, 'three');\r\n }\r\n function myLastFunction(arg1, callback) {\r\n   callback(null, 'done');\r\n }<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>\/\/\u5f02\u6b65\uff0c\u5982\u679c\u6ca1\u6fc0\u6d3b\u9519\u8bef\u8fd4\u56de\u7684\u7ed3\u679c\u662f one,two,thress,thress \u662f\u6309\u7167\u4e4b\u524d\u7684\u987a\u5e8f\u6392\u5e8f\u7684\uff0c\r\n\/\/\u8ddf\u6267\u884c\u7684\u65f6\u95f4\u987a\u5e8f\u65e0\u5173\u3002\r\n\r\n\/\/\u5982\u679c\u67d0\u4e2a\u51fd\u6570\u6709\u6fc0\u6d3b\u9519\u8bef\uff0c\u9519\u8bef\u7684\u56de\u8c03\u7acb\u9a6c\u6267\u884c\uff0c<span style=\"color: #ff0000;\">\u540e\u9762\u7684\u51fd\u6570\u4f9d\u7136\u6267\u884c<\/span>\u3002\r\n\r\nasync.<span style=\"color: #ff0000;\">parallel<\/span>([\r\n   function (callback) {\r\n      callback(null, 'one');\r\n   },\r\n   function (callback) {\r\n      console.log(22);\r\n      callback(null, 'two');\r\n   }, function (callback) {\r\n      console.log(33);\r\n      callback(null, 'thress');\r\n   }, function (callback) {\r\n      console.log(44);\r\n      callback(null, 'thress');\r\n   }],\r\n function (err, results) {\r\n     if (err) {\r\n        console.log('\u9519\u8bef\uff1a'+err);\r\n     } else {\r\n        console.log('\u6210\u529f\uff1a' + results);\r\n     }\r\n });<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>\/\/\u6279\u91cf\u4fee\u6539\u6570\u7ec4\u5185\u5bb9\uff0c\u529f\u80fd\u8ddfjquery\u4e2d\u7684map\u4e00\u6837\r\n\r\n async.<span style=\"color: #ff0000;\">map<\/span>(['file1', 'file2', 'file3'], function (item, callback) {\r\n     console.log(item); \/\/ file1,file2,file3\r\n     callback(null, item + 1);\r\n   }, function (err, results) {\r\n     if (err) {\r\n        console.log(err);\r\n     } else if (results) {\r\n        console.log(results); \/\/ [\"file11\", \"file21\", \"file31\"]\r\n     }\r\n });\r\n\r\n\r\n\u6269\u5c55\u529f\u80fd\r\nmapSeries(arr, iteratee, [callback])\r\nmapLimit(arr, limit, iteratee, [callback])<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>\/\/\u6548\u679c\u5c31\u662f\u7c7b\u4f3cfor\u5faa\u73af\u5b8c\u4e86\u4e4b\u540e\u5c31\u56de\u8c03\u4e00\u4e2a\u51fd\u6570\r\n\r\nvar count = 0;\r\nasync.<span style=\"color: #ff0000;\">during<\/span>(\r\n   function (callback) {\r\n     \/\/ console.log('\u5f53count\u7b49\u4e8e' + count+'\u65f6\uff0c\u6267\u884c\u4e86\u4e00\u4e9b\u4ee3\u7801'); \/\/\u4ee3\u7801\u653e\u8fd9\u91cc\u6267\u884c\u4e866\u6b21\r\n     return callback(null, count &lt; 5);\r\n   },\r\n   function (callback) {\r\n     count++;\r\n     \/\/ console.log('\u5f53count\u7b49\u4e8e' + count + '\u65f6\uff0c\u6267\u884c\u4e86\u4e00\u4e9b\u4ee3\u7801'); \/\/\u4ee3\u7801\u653e\u8fd9\u91cc\u6267\u884c\u4e865\u6b21(\u63a8\u8350\u653e\u8fd9\u91cc)\r\n     document.title = count;\r\n     setTimeout(callback, 1000);\r\n     \/\/ console.log(count);\r\n   },\r\n   function (err,sucess) { \/\/\u7b2c\u516d\u79d2\u65f6\u5019\u6267\u884c\u56de\u8c03\r\n     if (err) { } else { document.title = 'for\u5faa\u73af\u6210\u529f\u540e\u56de\u8c03'; }\r\n   }\r\n );<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>\/\/\u7c7b\u4f3cfor\u5faa\u73af\uff0c\u521b\u5efa\u5bf9\u8c61\r\n\r\nvar arr = [];\r\n function createUser(id, callback) {\r\n    callback(null, {  \/\/\u8fd9\u91cc\u5199\u7684\u5bf9\u8c61\u5c31\u662f\u6211\u4eec\u8981\u5faa\u73af\u521b\u5efa\u7684\r\n      id: 'user' + id\r\n    })\r\n }\r\n \/\/ generate 5 users\r\n async.<span style=\"color: #ff0000;\">times<\/span>(5, function (n, next) {\r\n    createUser(n, function (err, user) {\r\n       console.log(n); \/\/\u7d22\u5f15\r\n       console.log(user); \/\/\u5bf9\u8c61\r\n       next(err, user)\r\n    })\r\n }, function (err, users) {\r\n       arr = users;\r\n });\r\n\r\nconsole.log(arr);<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>\/\/\u540c\u6b65\uff0c\u8bbe\u7f6e\u4e3a1 \u4efb\u610f\u4e00\u4e2a\u51fd\u6570\u9519\u8bef\u6fc0\u6d3b\u540e\u9762\u7a0b\u5e8f\u4ecd\u7136\u53ef\u4ee5\u8fd0\u884c\uff0c\u90fd\u8fd0\u884c\u5b8c\u6210\u540e\u56de\u8c03\r\n\/\/\u5f02\u6b65\uff0c\u8bbe\u7f6e&gt;1\u7684\u6570\u5b57 \u4efb\u610f\u4e00\u4e2a\u51fd\u6570\u9519\u8bef\u6fc0\u6d3b\u540e\u9762\u7a0b\u5e8f\u4ecd\u7136\u53ef\u4ee5\u8fd0\u884c\uff0c\u90fd\u8fd0\u884c\u5b8c\u6210\u540e\u56de\u8c03\r\n\r\nvar q = async.<span style=\"color: #ff0000;\">queue<\/span>(function (task, callback) {\r\n   \/\/q.length() \/\/\u8fd4\u56de\u8fd8\u6709\u591a\u5c11\u4e2a\u6b63\u5728\u7b49\u5f85\u7684\u8981\u6267\u884c\u7684\u51fd\u6570\uff0c\u5047\u5982\u67093\u4e2a\u8fdb\u7a0b\uff0c\u7b2c\u4e00\u4e2a\u51fd\u6570\u5fc5\u987b\u5148\u6267\u884c\u540e\u624d\u80fd\u6267\u884c\u5230\u5b83\uff0c\u56e0\u4e3a\u4ed6\u67e5\u8be2\u7684\u662f\u7b49\u5f85\u7684\u51fd\u6570\u3002\r\n   \/\/ console.log(q.started); \/\/\u5224\u65ad\u6211\u4eec\u5b9a\u4e49\u7684\u8fd9\u4e2aq\u5bf9\u8c61\u662f\u5426\u5df2\u7ecf\u5f00\u59cb\u6267\u884c\u6574\u4e2a\u7a0b\u5e8f\uff0ctrue\u662f\u8fd9\u4e2a\u6574\u4e2a\u7a0b\u5e8f\u5f00\u59cb\u6267\u884c\u4e86\u3002\r\n  if (task.name == '\u5de5\u4eba1') {\r\n    setTimeout(function () {\r\n      console.log('hello ' + task.name);\r\n      callback(1);\r\n    }, 3000)\r\n  } else if (task.name == '\u5de5\u4eba2') {\r\n     setTimeout(function () {\r\n       console.log('hello ' + task.name);\r\n       callback(1);\r\n     }, 3000)\r\n   } else {\r\n      console.log('hello ' + task.name);\r\n      callback();\r\n    }\r\n},2); \/\/\u8fd9\u91cc\u8bbe\u7f6e\u5e76\u53d1\u6570\u67092\u4ee5\u4e0a\u7684\u5c31\u662f\u5f02\u6b65\u4e86\uff0c\u5982\u679c\u6ca1\u8bbe\u7f6e\u9ed8\u8ba4\u5c31\u662f1\uff0c\u4e5f\u5c31\u662f\u540c\u6b65\u4e86\r\n\r\n\r\n\r\n q.drain = function () { \/\/\u6240\u6709\u7684\u7a0b\u5e8f\u90fd\u6267\u884c\u5b8c\uff0c\u800c\u4e14\u4e0d\u7ba1\u6210\u4e0d\u6210\u529f\u90fd\u8981\u6267\u884c\u8fd9\u91cc\r\n    console.log('\u6700\u540e\u8fd9\u91cc\u603b\u8981\u6267\u884c');\r\n    \/\/ console.log(q.idle()); \/\/\u9ed8\u8ba4\u662ffalse\u8bf4\u660e\u7a0b\u5e8f\u5728\u6267\u884c\uff0c\u5982\u679c\u4e3atrue\u8bf4\u660e\u7a0b\u5e8f\u5df2\u7ecf\u7ed3\u675f\u4e86\u3002\r\n }\r\n\r\n\r\n q.empty = function () { \/\/\u603b\u662f\u5728\u6700\u540e\u4e00\u4e2a\u51fd\u6570\u6267\u884c\u5b8c\u6210\u4e4b\u524d\u6267\u884c\u3002\u4f8b\u5982\uff0c\u67093\u4e2a\u51fd\u6570\uff0c\u5728\u524d2\u4e2a\u51fd\u6570\u6267\u884c\u5b8c\u6210\u540e\u5c31\u7acb\u9a6c\u6267\u884c\u3002\r\n    console.log('\u603b\u662f\u5728\u6700\u540e\u4e00\u4e2a\u51fd\u6570\u6267\u884c\u5b8c\u6210\u4e4b\u524d\u6267\u884c');\r\n    \/\/ console.log(q.idle()); \/\/\u9ed8\u8ba4\u662ffalse\u8bf4\u660e\u7a0b\u5e8f\u5728\u6267\u884c\uff0c\u5982\u679c\u4e3atrue\u8bf4\u660eempty\u7a0b\u5e8f\u5df2\u7ecf\u7ed3\u675f\u4e86\u3002\r\n }\r\n\r\n\r\n q.push({ name: '\u5de5\u4eba1' }, function (err) {\r\n    if (err) {\r\n       console.log('\u5de5\u4eba1 \u6ca1\u5b8c\u6210'); \/\/\u5355\u8fdb\u7a0b\u5931\u8d25\u56de\u8c03\r\n      \/\/ill(); \/\/\u5728\u6b64\u4ee3\u7801\u540e\u9762\u7684\u6240\u6709\u51fd\u6570\u90fd\u4e0d\u4f1a\u6267\u884c\uff0c\u5305\u62ecq.drain\r\n      \/\/.pause() \/\/\u6b64\u4ee3\u7801\u540e\u9762\u7684\uff0c\u51fd\u6570\u6682\u65f6\u505c\u6b62\u8fd0\u884c\r\n      \/\/q.paused \/\/true,\u8868\u793a\u7a0b\u5e8f\u6682\u505c false\uff0c\u8868\u793a\u6ca1\u6682\u505c \r\n      \/\/ setTimeout(function () { q.resume() }, 13000); \/\/13\u79d2\u540e\u6062\u590d q.pause\u548cq.resume\u914d\u5408\u4f7f\u7528\r\n    } else {\r\n       console.log('\u5de5\u4eba1 \u5b8c\u6210'); \/\/\u5355\u8fdb\u7a0b\u6210\u529f\u56de\u8c03\r\n    }\r\n });\r\n\r\n\r\n\r\nq.push({ name: '\u5de5\u4eba2' }, function (err) {\r\n    if (err) {\r\n      console.log('\u5de5\u4eba2 \u6ca1\u5b8c\u6210');\r\n    } else {\r\n      console.log('\u5de5\u4eba2 \u5b8c\u6210');\r\n    }\r\n });\r\n\r\n\r\n\r\nq.push({ name: '\u5de5\u4eba3' }, function (err) {\r\n    if (err) {\r\n       console.log('\u5de5\u4eba3 \u6ca1\u5b8c\u6210');\r\n    } else {\r\n       console.log('\u5de5\u4eba3 \u5b8c\u6210');\r\n    }\r\n });\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/github.com\/caolan\/async\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/caolan\/async<\/a><\/p>\n<p><a href=\"http:\/\/www.easyui.info\/archives\/1788.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.easyui.info\/archives\/1788.html<\/a><\/p>\n<p><a href=\"https:\/\/cnodejs.org\/topic\/54acfbb5ce87bace2444cbfb\" target=\"_blank\" rel=\"noopener\">https:\/\/cnodejs.org\/topic\/54acfbb5ce87bace2444cbfb<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>js jquery \u5f02\u6b65 \u56de\u8c03\u00a0Deferred promise \u5730\u72f1\u56de\u8c03\u00a0\u5730\u72f1 \u56de\u8c03 \u8bf4\u5230js\u7684\u5f02\u6b65\u5c31\u4f1a\u8ba9\u6211 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-4848","post","type-post","status-publish","format-standard","hentry","category-11"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/4848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4848"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/4848\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}