Node.js and CPU intensive requests

前端 未结 5 2158
囚心锁ツ
囚心锁ツ 2020-12-02 03:42

I\'ve started tinkering with Node.js HTTP server and really like to write server side Javascript but something is keeping me from starting to use Node.js for my web applicat

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 03:49

    Couple of approaches you can use.

    As @Tim notes, you can create an asynchronous task that sits outside or parallel to your main serving logic. Depends on your exact requirements, but even cron can act as a queueing mechanism.

    WebWorkers can work for your async processes but they are currently not supported by node.js. There are a couple of extensions that provide support, for example: http://github.com/cramforce/node-worker

    You still get you can still reuse modules and code through the standard "requires" mechanism. You just need to ensure that the initial dispatch to the worker passes all the information needed to process the results.

提交回复
热议问题