audreyt / node-webworker-threads

Lightweight Web Worker API implementation with native threads
https://npmjs.org/package/webworker-threads
Other
2.3k stars 149 forks source link

require in the thread function cause error????? #113

Closed wjianwei126 closed 7 years ago

wjianwei126 commented 8 years ago

if you require('fs') is the thread function it will say FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place

brodycj commented 8 years ago

Use of require within a thread function is currently not supported. To accomplish this would need some support from Node.js.

icodeforlove commented 8 years ago

@wjianwei126 you can try to convert the whole module into a string and pass it to the worker.

https://github.com/icodeforlove/task.js/issues/20#issuecomment-236612517 https://github.com/icodeforlove/node-require-bundle

FabioSilvaBRZ commented 7 years ago

Do not you workaround this "FATAL ERROR: HandleScope::HandleScope" by using pools??? For example, if you call threadPool.any.eval(any_func()); you can use all your developed materials... including the require(s), no?

davisjam commented 7 years ago

require is not part of JavaScript, but is rather a feature of Node.js. webworker-threads imitates the WebWorker API so that your code can be used in both the browser and the Node.js environment. If you want to use require, your code won't be portable anyway, in which case you'd be better off using the cluster module or a child process-based pool with full require support.