我听说nodejs不适合应用复杂逻辑的应用程序。我可以举个例子吗?
我也听说过关于cpu密集型任务的相同事情。我也可以得到一个基本的例子吗?
答案 0 :(得分:2)
你的问题不是很正确。 Javascript非常适合复杂的逻辑。但是javascript是单线程的。这意味着可以假设您在“metacode”中编写服务器。
var httpServer = require('http');
httpServer.onRequest(respond);
function respond(requestContext) {
thread.sleep(2000) // or do some heavy calculations which takes while
// like sorting array with 100000000000 elements
sendResponse();
};
这意味着您的服务器根本不会为其他客户端提供服务,因为整个应用程序(只有单个线程)很忙。 所以它不是复杂的逻辑。这是关于繁重的计算。