Pass arguents to worker
See original GitHub issueHi! 😃
I need to pass simple arguments to a worker. Somewhat like that:
max = 42;
var w = new Worker(function () {
for (var i = 0; i < max; i++) {
// Do something...
}
}
max
is in a different context than what is accessible from within the worker. How can I pass its value (or alternatively, the main context) to the worker?
The only way I would see is to use w.postMessage(max)
after creating w
, and have the thread inside of w
block until it receives this first message. But that seems rather inelegant.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
javascript web workers - how do I pass arguments?
How do I pass an argument to a web worker though using this basic example? contents of worker.js: function doSomething() { postMessage( '...
Read more >How can you pass additional args to a worker function?
How to pass the additional args and kwargs in execute_this_fn below is ... worker = Worker(lambda :self.execute_this_fn(arg1, arg2, kwarg1).
Read more >How to pass function to Web Workers - Localazy
The most scalable option I've found is to have two stable parameters, one for functions and one for their arguments a simply send...
Read more >Passing ARGS to multiple workers - Julia Discourse
I am trying to pass an argument from the terminal to a program that uses multiple cores. But ARGS appear to be visible...
Read more >Passing arguments from command line ( or worker.main() ) all ...
I am currently looking at a way to pass a parameter from the command line ( or worker.main() ) to the task (...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’re right. That doesn’t work with workers. You will probably need to pass in the argument with a post message (I verified this worked by running it):
feel free to start a new issue, someone might be able to help.