multithreading - node.js +express +threads_a_gogo 阻塞请求

标签 multithreading node.js express

我在node js中有一段代码需要几秒钟才能完成,所以我开始使用threads_a_gogo模块(https://github.com/xk/node-threads-a-gogo)来不阻止http请求。我花了很多时间试图找出为什么威胁生成不起作用,因为我的请求仍然被阻止。

app.post('/results.html', function(req, res){


    if( config.debug )
        console.log("thread created");
    var t = threads.create();
    var r = new rounds();
    t.eval( r.start(req,res), function(err, result) {

        r.finish( res );
        //t.destroy();
        if( config.debug )
            console.log("thread destroyed");
    });
    console.log("request finished");



});

console.log("请求完成");仅在新线程完成后显示,但它应该几乎在请求完成时显示,并且在进程完成之前阻止对服务器的请求。

知道我做错了什么吗?

谢谢

最佳答案

您实际上是在主线程中执行r.start(req,res),然后将返回值传递给t.evaleval 接受一个字符串,然后在线程全局范围内执行。像这样的东西应该有效:

t.eval('var start =' + r.start.toString()).eval('start()'), function(err, result) { });

关于multithreading - node.js +express +threads_a_gogo 阻塞请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20400256/

相关文章:

node.js - Node Js 和 Express : Where can I find free simple projects to learn and read the code?

Azure 上的 Node.js 集群 : ENOTSUP - cannot write to IPC channel

c# - 使用两个线程写入文本框

c# - Thread.Sleep(1) 的目的?

c# - 如何在bho中的异步httpwebrequest回调中访问ui线程

javascript - 使用 jQuery 在服务器端操作 Wordpress 数据库

c# - 获取和释放锁定期间隐含的语义?

node.js - NodeJS 错误封装

javascript - 有人能区分这两个 Express-React-Node 应用程序之间的区别吗?

javascript - 如何在 angularJS 中获取 Expess 对象 cookie?