Comments (7)
So just to be clear, even if we use browserify to package required modules into something that can be consumed by importScripts, it won't work -- it seems like we can't use modules inside of web workers.
Take the following code:
// example_mod.js
var my_mod = require('build/Release/my_module');
and say we run browserify example_mod.js > example_import.js
If I then have the following:
var mod_work = new Threads.Worker(function() {
function performWork() {
importScripts('example_import.js');
return my_mod.run();
}
this.onmessage = function(event) {
postMessage(performWork());
}
});
mod_work.postMessage();
Then the call to my_mod.run()
hangs indefinitely without being called.
Am I misunderstanding how to use web workers, or can we really not use modules inside of thread workers even if we wrap their code in something that can be called by importScripts
?
from node-webworker-threads.
for the love of all things holy can someone just create "require"
functionality in webworkers?
On Jun 5, 2016 8:18 AM, "唐鳳" [email protected] wrote:
Hmm, this looks legitimate and should work for pure-javascript modules. If
I set example_import.js to:var my_mod = {run: function(){ return 123 }}
and change the postMessage(performWork()); line to:
console.log(performWork());
Then I do find it printed out. However if build/Release/my_module is a
binary module (built by node-gyp or similar) then indeed, we have no way
of loading them currently.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#15 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ACDIYCPUsdYwvTosm10ercV98LrVNtorks5qIujHgaJpZM4Aqh3K
.
from node-webworker-threads.
Hi, currently as per Web Worker spec, only importScripts
is supported.
To package node modules into .js files suitable for importScripts
, perhaps give https://github.com/azer/onejs a try?
from node-webworker-threads.
@audreyt a small example or snippet would be appreciated.
from node-webworker-threads.
Hmm, this looks legitimate and should work for pure-javascript modules. If I set example_import.js
to:
var my_mod = {run: function(){ return 123 }}
and change the postMessage(performWork());
line to:
console.log(performWork());
Then I do find it printed out. However if build/Release/my_module
is a binary module (built by node-gyp
or similar) then indeed, we have no way of loading them currently.
from node-webworker-threads.
I dont have the expertise to do this but audrey you probably do or someone
around here does. it would be so frickin' useful to have require abilities
in webworkers.
On Jun 5, 2016 10:38 AM, [email protected] wrote:
for the love of all things holy can someone just create "require"
functionality in webworkers?
On Jun 5, 2016 8:18 AM, "唐鳳" [email protected] wrote:Hmm, this looks legitimate and should work for pure-javascript modules.
If I set example_import.js to:var my_mod = {run: function(){ return 123 }}
and change the postMessage(performWork()); line to:
console.log(performWork());
Then I do find it printed out. However if build/Release/my_module is a
binary module (built by node-gyp or similar) then indeed, we have no way
of loading them currently.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#15 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ACDIYCPUsdYwvTosm10ercV98LrVNtorks5qIujHgaJpZM4Aqh3K
.
from node-webworker-threads.
@the1mills Please consider using https://www.npmjs.com/package/tiny-worker which does support require
through child processes.
from node-webworker-threads.
Related Issues (20)
- Can't install with yarn HOT 4
- Implement removeEventListener()
- importScripts() should resolve against webworker file not cwd HOT 1
- npm install fails with node 11 HOT 2
- corrupted double-linked list: webworker-threads/build/Release/WebWorkerThreads.node
- Terminating worker threads - the correct way ?
- thread Pool do not support to run a function with operation buffer? HOT 1
- npm install webworker-threads fails. node: 8.11.2, npm: 5.6.0. HOT 3
- How to debug webworkerthread.cc file HOT 1
- Error while installing webworker on ubuntu
- Accessing any unknown variable inside worker, program is not responding at all.
- npm install --global --production windows-build-tools HOT 1
- Issue installing on macOS HOT 6
- npm install error with node 12 HOT 3
- Build Failing HOT 1
- Can't install on macOS Catalina HOT 2
- Could not install on windows 10 HOT 1
- Failed to install [email protected] using npm HOT 11
- Can you provide a version support to node 10 +
- Can you provide a support for node 19 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-webworker-threads.