控制台日志图片 https://i.stack.imgur.com/TKhfa.png
const express = require('express');
const app = express();
const port = 4444;
app.get('/', async (req, res) => {
console.log('got request');
await new Promise(resolve => setTimeout(resolve, 10000));
console.log('done');
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
如果我同时点击 get 请求 http://localhost:4444 三次,那么它会返回如下日志
got request
done
got request
done
got request
done
由于节点事件循环和回调队列位于进程线程外部,它不应该以下面的方式返回输出吗? (也许我错了,但需要对 Nodes 内部结构有一些了解)和 Node 中的外部 api 请查找附图JavaScript 运行时环境 https://i.stack.imgur.com/ZGd1d.jpg
got request
got request
got request
done
done
done
谢谢https://stackoverflow.com/users/5330340/phani-kumar https://stackoverflow.com/users/5330340/phani-kumar
我明白了它被阻止的原因。我正在用 chrome 测试这个。我正在从 Chrome 浏览器发出 get 请求,当我在 Firefox 中尝试相同的操作时,它按预期工作。
原因是因为这个
Chrome 会锁定缓存并等待查看一次请求的结果,然后再再次请求同一资源。
对同一资源发出多个请求时 Chrome 会停止? https://stackoverflow.com/questions/27513994/chrome-stalls-when-making-multiple-requests-to-same-resource
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)