web-worker

Opinion about synchronous requests in web workers

痴心易碎 提交于 2019-11-27 02:45:07
问题 I want to know what do you think about this. Is recommended to use synchronous requests (XMLHttpRequest) in a web worker? What problems can I find? I have been testing this in my app and I haven't find any trouble. But I'm afraid of this synchronus behaviour because of old experiences with jQuery and AJAX. My app gets a big amount of data from several tables in a database, and this requires a time. For each bunch of data retrieved from a table, I need to instantly process it to not delay the

Get number of CPU cores in JavaScript?

扶醉桌前 提交于 2019-11-27 02:01:49
问题 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? 回答1: Yes, navigator.hardwareConcurrency. Supported natively in Chrome, Firefox, Edge, Opera, and Webkit; supported in all browsers with a polyfill. 回答2: No, there isn't, unless you use some ActiveX. 回答3: You can try to estimate the number of cores with: https://github.com/oftn/core-estimator demo: http://eligrey.com/blog/post/cpu-core-estimation

What happens to an HTML5 web worker thread when the tab is closed while it's running?

霸气de小男生 提交于 2019-11-27 01:51:55
问题 I'm wondering what happens when a user closes the tab which spawned the worker thread, while the thread is still working. Does it halt everything? If so, is there a way to run the thread in the background even when the tab is closed? 回答1: Yes it halts everything, a (dedicated) worker can't outlive its owner. If you use a shared worker, which can have multiple owners, the worker will only stay alive as long as at least one owner is alive. This is the case even if you pass on the entangled

Is it feasible to do an AJAX request from a Web Worker?

不打扰是莪最后的温柔 提交于 2019-11-27 01:07:01
问题 I do not seem to be able to use jQuery in my webworker, I know there must be a way to do it with XMLHttpRequest , but it seems like that might not be a good option when I read this answer. 回答1: Of course you can use AJAX inside of your webworker, you just have to remember that an AJAX call is asynchronous and you will have to use callbacks. This is the ajax function I use inside of my webworker to hit the server and do AJAX requests: var ajax = function(url, data, callback, type) { var data

Passing objects to a web worker

孤人 提交于 2019-11-27 00:36:51
I'm trying to pass an object to a web worker through the postMessage function. This object is a square that has a couple of functions to draw himself on a canvas and some other things. The web worker must return an array of this objects. The problem is that when I call the postMessage function with this object, I get an this error: Uncaught Error: DATA_CLONE_ERR: DOM Exception 25 I get this both sending the object to the worker and the other way around. I think the error is because javascript must serialize the object, but can't do it because the object has functions built-in. Does anyone ever

What's the difference between Shared Worker and Worker in HTML5?

妖精的绣舞 提交于 2019-11-27 00:20:06
问题 After reading this blog post: http://www.sitepoint.com/javascript-shared-web-workers-html5/ I don't get it. What's the difference between a Worker and a SharedWorker ? 回答1: Very basic distinction: a Worker can only be accessed from the script that created it, a SharedWorker can be accessed by any script that comes from the same domain. 回答2: SharedWorker's seem to have more functionality then Worker. Among that functionality is : A shared global scope. All SharedWorker instances share a single

Web Workers and Canvas

纵饮孤独 提交于 2019-11-27 00:14:23
Are web workers allowed to access a canvas object? tsauerwein Small update, as the question is now more than half a year old: In Chrome/Chromium 6 you can now send a canvas' ImageData object to a web worker, let the web worker make changes to the object and then write it back to the canvas using putImageData(..) . Google's Chromabrush does it this way, the source-code can be found here: Main thread Web worker Update: The latest development snapshots of Opera (10.70) and Firefox (4.0b1) also support passing ImageData objects to a web worker. Update 2017: Actual links from Github (easier to find

Chrome can't load web worker

六眼飞鱼酱① 提交于 2019-11-26 23:49:36
I am working on a project that uses a web worker. In my head section I have this code: var worker = new Worker("worker.js"); // More code This works fine in Safari, but Chrome reports the following error: Uncaught SecurityError: Failed to create a worker: script at '(path)/worker.js' cannot be accessed from origin 'null'. Why does this work perfectly in Safari but not Chrome? How do I fix this? Thank you. Nobel Chicken Chrome doesn't let you load web workers when running scripts from a local file. Tomáš Zato I use a workaround. Chrome blocks Worker but not <script> . Hence the best way to make

Web workers and accessing object attached to the window object

感情迁移 提交于 2019-11-26 23:24:41
问题 I have an ember application that I create like this: window.App = Ember.Application.create({}); I want to do some background processing on a web worker. How can I get access to the window object or some other global object in the separate web worker thread? 回答1: Short answer. You can't. The only resources available to web workers are that which they load from JavaScript files using importScripts() or anything that is passed to them via postMessage() . You can however now pass Objects to them.

Sharing websocket across browser tabs?

南楼画角 提交于 2019-11-26 22:38:35
问题 We want to have one socket per browser rather than one per tab in a browser. How can we achieve it? I read about shared web workers which was promising. A reference for that too is appreciated. Unfortunately shared web workers are not yet implemented by mozilla or internet explorer to the best of my knowledge. So what to do in this case ? We are working on node.js on server side. 回答1: After seeing this question, I've finally implemented sharing socket and added to my library a few days ago.