开发者

nodejs and node-webworker

开发者 https://www.devze.com 2023-01-25 03:35 出处:网络
so this neat library is helping me with some things, but its acting strange with others. I can see in its github repo history:

so this neat library is helping me with some things, but its acting strange with others.

I can see in its github repo history: https://github.com/pgriess/node-webworker/commit/3cd733ec1df946a1dc55b5fcde7388097ac0f6a2

that every child worker gets a console properly exported into its context. my understanding is that this is so that when (for example) the child worker calls console.log() that will show in stdout of the parent process (the one that spawned the child worker). Am I correct to assume this?

Im asking this because I am using console.log() in workers but cannot view the output on my terminal stdout.

thx


update:

so I found a deeper issue here. I was debugging the node-webworker source today and found an incompatibility with coffeescript in general, which is what I use... I posted an issue (and proposed solution) on the github node-webworker repo:

https://github.com/pgriess/node-webworker/issues#issue/14

explanation I posted on github:

"since the coffeescript wraps every file it compiles with a lambda block: (function() { ... }) all handlers created in the global scope in the coffeescript file (onmessage,onerror) are actually not global but wrapped in that same lambda block, and therefore 开发者_运维知识库not visible to the webworker-child.js setup script... hence workerCtx.onmessage is undefined, and so is onerror, and so the worker does not receive messages from the master...

coffeescript is gaining widespread use, and their decision to wrap every script in a lambda block to protect the global namespace is a valid one. hence I think that, in node-webworker, onmessage/onerror handlers should not be declared as they are currently as global vars, but instead should be passed in to some sort of global init() function (that would be attached to workerCtx when the worker is being setup inside webworker-child.js). that way it wouldnt matter where they're declared..."

new:

just tested a patch on my local repository and the proposed solution with the init_handlers() function (issue 14 ticket on github) does solve the incompatibility with coffeescript

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号