web-worker

Degrading gracefully with Web Workers

So I'm starting to hear more and more about Web Workers. I think it's absolutely fantastic, but the question I haven't seen anyone really tackle so far is how to support older browsers that do not yet have support for the new technology. The only solution I've been able to come up with so far is to make some sort of wrapper around the ...

Combining the power of Processing.js and Web Workers

I've been doing some reading about two (relatively) new concepts in the Javascript language - Web Workers and John Resig's awesome Processing.js (well, not really a new 'Javascript concept', but you get my idea). Some great examples of both wander the internets, but I have yet to find one that employs both techniques effectively. It look...

How do you encode an Object in a Web Worker for it to be passed via postMessage?

Internally, Firefox will JSON encode an object passed via postMessage to and from the Web Worker. However, this only works in Trunk builds of Firefox (3.6+) and not in Firefox 3.5, so the question is really how to add backwards support of this operation to the current platform. The window.atob() and window.btoa() methods had been suggest...

is postMessage JSON encoded/decoded in Google Chrome as it is in Firefox?

I know its part of the HTML5 spec, but sometimes WebKit doesn't conform to the latest draft of the spec. ...

Are Web Workers themselves allowed to have Web Worker threads?

This would seem to be the case in Firefox 3.5+, there I can instantiate a Web Worker, and inside the worker, spawn another thread. However, the code will not work in Google Chrome, leading me to believe this is either a Mozilla proprietary extension to the spec or that Chrome has not fully implemented the spec. So which is it? ...

How do I talk to Firebug from a Web Worker?

My web workers are becoming increasingly complicated and I'm sorely missing Firebug access while working with them. This: console.log("test"); Does not produce anything from a web worker. I've also tried the following: dump("test"); And that doesn't produce any output either. Firefox version: Mozilla/5.0 (Macintosh; U; Intel Mac...

Web Workers and Canvas

Are web workers allowed to access a canvas object? ...

Sharing variables between web workers? [global variables?]

Is there any way for me to share a variable between two web workers? (Web workers are basically threads in Javascript) In languages like c# you have: public static string message = ""; static void Main() { message = "asdf"; new Thread(mythread).Run(); } public static void mythread() { Console.WriteLine(message); //outputs "asdf" } ...

window.alert in worker thread

If I put a window.alert on a webworker client, then the background worker stops working. Why is this so? i.e. The caller: var worker = new Worker("worker.js"); // Watch for messages from the worker worker.onmessage = function(e){ // The message from the client: e.data }; worker.postMessage("start"); The client (worker.js) onmess...

What are the use-cases for Web Workers?

I am looking for real-world scenarious for using Web Workers API. ...

Web workers - How do they work ?

I'm trying to understand this example: HTML (main code): <html> <title>Test threads fibonacci</title> <body> <div id="result"></div> <script language="javascript"> var worker = new Worker("fibonacci.js"); worker.onmessage = function(event) { document.getElementById("result...

Who has proposed Web Workers

I wonder who is the first person that has proposed modern Web Workers API. I find web workers, well, rather an ugly construction, I just can get the idea of calling workers from a separate file. I can see no any real danger in spawning a thread from an anonymous function. But I'm asking this question without any intention to start flami...

How to prevent HTML5 Web Workers from locking up thus correctly responding to messages from parent

Hi guys, I'm using web workers to do some CPU intensive work but have the requirement that the worker will respond to messages from the parent script while the worker is still processing. The worker however will not respond to messages while it is locked in a processing loop, and I have not found a way to say poll the message queue. ...

Race-condition with web workers when setting onmessage handler?

Please consider the following code and the explanation from this Mozilla tutorial "Using web workers": var myWorker = new Worker('my_worker.js'); myWorker.onmessage = function(event) { print("Called back by the worker!\n"); }; Line 1 in this example creates and starts running the worker thread. Line 2 sets the onmessage hand...

Web Workers and Sparklines

I know that Web Workers don't have access to the DOM, but I was wondering if there was any way they could render a Sparkline graph behind the scenes and pass it back. If not, is there ANY way I could use Web Workers to speed up the processing of around a million sparklines? I'm trying to improve performance (see this question) ...

Get number of CPU cores in JavaScript?

Is there a way to determine the number of available CPU cores in JavaScript, so that you could adjust the number of web workers depending on that? ...

Does it make sense to use Web Workers for a game?

Hi, I am working on a game that has AI logic, movement, etc and drawing. Does it make sense to calculate moving and AI logic using Web Workers? But how do I do that -- because the workers need to know so much about the main thread like the positions of certain objects for collisions, amount of bullets, etc. It feels like impossible beca...

Node.js and CPU intensive requests

I've started tinkering with Node.js HTTP server and really like to write server side Javascript but something is keeping me from starting to use Node.js for my web application. I understand the whole async I/O concept but I'm somewhat concerned about the edge cases where procedural code is very CPU intensive such as image manipulation o...

Asynchronous POST request from a Firefox's web worker

Hello all, I am trying to make an asynchronous request with POST method from a web worker used in my extension. The thing is that it does not work for me. On the server side I have PHP script listening for data in $_POST variable. Although I am able to establish connection to the server, and even pass some data in URL (GET), the $_POST ...

Cross-Origin Resource Sharing (CORS) using JSONP and Web Workers

Hi, I am looking for solution how to get/send the data from/to another domain using JSONP in the Web Workers. Since the Web Workers have not access to the DOM it is not possible to append the <script> tag with the url and callback parameter to the <head> tag from Web Workers. Does anybody know, how to get/post the data from/to another...