【问题标题】:Using await in code for a child process will make only that child process or all the other child process for execution?在子进程的代码中使用 await 只会使该子进程或所有其他子进程执行?
【发布时间】:2019-05-25 08:10:31
【问题描述】:

我在代码中为我的一个子进程使用 await。那么当这个被执行时,所有其他子进程会停止执行还是只有这个子进程会停止?

我在代码中使用 cluster.fork 和 await 用于我的子进程。

【问题讨论】:

  • 你到底是什么awaiting?您是否手动构建了一个 Promise?

标签: javascript node.js node-cluster


【解决方案1】:

不,您的await 对其他进程没有影响。

但您似乎有一个误解:await 不仅不会阻止您使用cluster.fork 获得的其他进程,而且它也不会停止您当前的进程。

await 之后的代码在传递的 Promise 解决之前不会执行,但其他 Promise 可能在此之前解决,或者其他事件可能由底层 IO 系统产生,即使在同一过程。

记住:节点甚至在节点集群系统之前就能够处理并发请求。

相关:Why node.js is fast when it's single threaded?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    • 1970-01-01
    • 2015-03-31
    相关资源
    最近更新 更多