nodejs中process.nextTick里面的console日志顺序

bdawn 2021-01-23 04:00:42

const fs = require('fs');

fs.readFile(__filename, () => {
process.nextTick((e) => {
console.log(e)
console.error(e)
},new TypeError('argument should be string'))
setImmediate(() => {
console.log('immediate');
});
});


输出结果如下
TypeError: argument should be string
at D:\projectOther\mylib\src\test.js:7:5
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
immediate
TypeError: argument should be string
at D:\projectOther\mylib\src\test.js:7:5
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)


为什么执行顺序是先console.log(e),然后console.log('immediate'),最后console.error(e)
...全文
67 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧