{"id":2517,"date":"2018-02-23T14:14:47","date_gmt":"2018-02-23T06:14:47","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2517"},"modified":"2018-02-23T14:14:47","modified_gmt":"2018-02-23T06:14:47","slug":"process-nexttick-%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2517","title":{"rendered":"process.nextTick() \u6559\u7a0b"},"content":{"rendered":"<p>\n\tprocess.nextTick() \u662f Node \u7684\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u8ba9\u4efb\u52a1\u53ef\u4ee5\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u8fd0\u884c\u3002\u5176\u4e2d Node \u4e00\u5171\u63d0\u4f9b\u4e864\u4e2a\u5b9a\u65f6\u5668\uff0c\u5b83\u4eec\u5206\u522b\u662f setTimeout()\u3001setInterval()\u3001setImmediate()\u3001process.nextTick()\u3002\u672c\u6587\u4e3b\u8981\u8bb2\u89e3process.nextTick() \u7684\u7528\u6cd5\u548c\u6559\u7a0b\u3002\n<\/p>\n<h2>\n\tprocess.nextTick()<br \/>\n<\/h2>\n<p>\n\tprocess.nextTick\u8fd9\u4e2a\u540d\u5b57\u6709\u70b9\u8bef\u5bfc\uff0c\u5b83\u662f\u5728\u672c\u8f6e\u5faa\u73af\u6267\u884c\u7684\uff0c\u800c\u4e14\u662f\u6240\u6709\u5f02\u6b65\u4efb\u52a1\u91cc\u9762\u6700\u5feb\u6267\u884c\u7684\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"process.nextTick\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2018\/bg2018022302.png\" style=\"width: 352px;height: 131px\" \/>\n<\/p>\n<p>\n\tNode \u6267\u884c\u5b8c\u6240\u6709\u540c\u6b65\u4efb\u52a1\uff0c\u63a5\u4e0b\u6765\u5c31\u4f1a\u6267\u884cprocess.nextTick\u7684\u4efb\u52a1\u961f\u5217\u3002\u6240\u4ee5\uff0c\u4e0b\u9762\u8fd9\u884c\u4ee3\u7801\u662f\u7b2c\u4e8c\u4e2a\u8f93\u51fa\u7ed3\u679c\u3002\n<\/p>\n<pre class=\"brush:jscript;\">\r\nprocess.nextTick(() =&gt; console.log(3));<\/pre>\n<p>\n\t\u57fa\u672c\u4e0a\uff0c\u5982\u679c\u4f60\u5e0c\u671b\u5f02\u6b65\u4efb\u52a1\u5c3d\u53ef\u80fd\u5feb\u5730\u6267\u884c\uff0c\u90a3\u5c31\u4f7f\u7528process.nextTick\u3002\n<\/p>\n<p>\n\t\u6839\u636e\u8bed\u8a00\u89c4\u683c\uff0cPromise\u5bf9\u8c61\u7684\u56de\u8c03\u51fd\u6570\uff0c\u4f1a\u8fdb\u5165\u5f02\u6b65\u4efb\u52a1\u91cc\u9762\u7684&quot;\u5fae\u4efb\u52a1&quot;\uff08microtask\uff09\u961f\u5217\u3002<br \/>\n\t\u5fae\u4efb\u52a1\u961f\u5217\u8ffd\u52a0\u5728process.nextTick\u961f\u5217\u7684\u540e\u9762\uff0c\u4e5f\u5c5e\u4e8e\u672c\u8f6e\u5faa\u73af\u3002\u6240\u4ee5\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u603b\u662f\u5148\u8f93\u51fa3\uff0c\u518d\u8f93\u51fa4\u3002\n<\/p>\n<pre class=\"brush:jscript;\">\r\nprocess.nextTick(() =&gt; console.log(3));\r\nPromise.resolve().then(() =&gt; console.log(4));\r\n\/\/ 3\r\n\/\/ 4<\/pre>\n<p>\n\t\u6ce8\u610f\uff0c\u53ea\u6709\u524d\u4e00\u4e2a\u961f\u5217\u5168\u90e8\u6e05\u7a7a\u4ee5\u540e\uff0c\u624d\u4f1a\u6267\u884c\u4e0b\u4e00\u4e2a\u961f\u5217\u3002\n<\/p>\n<pre class=\"brush:jscript;\">\r\nprocess.nextTick(() =&gt; console.log(1));\r\nPromise.resolve().then(() =&gt; console.log(2));\r\nprocess.nextTick(() =&gt; console.log(3));\r\nPromise.resolve().then(() =&gt; console.log(4));\r\n\/\/ 1\r\n\/\/ 3\r\n\/\/ 2\r\n\/\/ 4<\/pre>\n<p>\n\t\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0c\u5168\u90e8process.nextTick\u7684\u56de\u8c03\u51fd\u6570\uff0c\u6267\u884c\u90fd\u4f1a\u65e9\u4e8ePromise\u7684\u3002<br \/>\n\t\u81f3\u6b64\uff0c\u672c\u8f6e\u5faa\u73af\u7684\u6267\u884c\u987a\u5e8f\u5c31\u8bb2\u5b8c\u4e86\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2517\">process.nextTick() \u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>process.nextTick() \u662f Node \u7684\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u8ba9\u4efb\u52a1\u53ef\u4ee5\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u8fd0\u884c\u3002\u5176\u4e2d Node  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[1106,1054,1415,1555,1604],"class_list":["post-2517","post","type-post","status-publish","format-standard","hentry","category-html5","tag-javascript","tag-node-emoji","tag-node-js","tag-nodejs","tag-settimeout"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2517"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2517\/revisions"}],"predecessor-version":[{"id":2518,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2517\/revisions\/2518"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}