web-worker

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

牧云@^-^@ 提交于 2019-11-28 07:34:17
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? 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 MessagePort to another window (i.e. owner of the message port is not the owner of the worker). So, with shared

Get number of CPU cores in JavaScript?

谁说胖子不能爱 提交于 2019-11-28 07:07:57
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? Yes, navigator.hardwareConcurrency . Supported natively in Chrome, Firefox, Edge, Opera, and Webkit; supported in all browsers with a polyfill . No, there isn't, unless you use some ActiveX. 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-with-javascript Here's a fairly quick concurrency estimator I hacked together... it hasn't undergone much testing yet:

What happens to a Web Worker if I close the page that created this Web Worker?

泪湿孤枕 提交于 2019-11-28 06:56:25
Let's say I have a page called Main.html that creates a web worker. If I close the Main page by changing window.location, would the web worker be terminated or would the web worker be still running? How does Firefox or Chrome choose to "handle long-running Worker tasks after the page has closed"? If the worker's task is to send a very quick POST request, for this case, does the browser terminate the worker immediatly after the page is closed or does the browser allow the worker to finished its POST request? Short answer: This behavior is implementation-defined, and the specification allows

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

半腔热情 提交于 2019-11-28 04:18:17
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 ? 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. SharedWorker's seem to have more functionality then Worker. Among that functionality is : A shared global scope. All SharedWorker instances share a single global scope. W3C Spec: SharedWorker Worker WHATWG Spec: SharedWorker Worker A shared worker can work with

Since JavaScript is single-threaded, how are web workers in HTML5 doing multi-threading?

核能气质少年 提交于 2019-11-28 04:04:46
I've been reading about web workers in HTML5, but I know JavaScript is single-threaded. My question is: How are web workers doing multi-threaded work then? or how are they simulating it if it's not truely multi-threaded? Doesn't seem clear to me here. As several comments have already pointed out, Workers really are multi-threaded. Some points which may help clarify your thinking: JavaScript is a language, it doesn't define a threading model, it's not necessarily single threaded Most browsers have historically been single threaded (though that is changing rapidly: IE , Chrome , Firefox ), and

What can service workers do that web workers cannot?

纵饮孤独 提交于 2019-11-28 03:14:53
What can service workers do that web workers cannot? Or vice versa? It seems that web workers are a subset of the functionality of service workers. Is this correct? Buksy There is a big difference in what they are intended for: Web Workers Web Workers provide a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering with the user interface. In addition, they can perform I/O using XMLHttpRequest (although the responseXML and channel attributes are always null). Once created, a worker can send messages to the JavaScript code that

What are the use-cases for Web Workers? [closed]

本小妞迷上赌 提交于 2019-11-28 02:36:21
I am looking for real-world scenarious for using Web Workers API . DVK John Resig (of jQuery fame) has a bunch of interesting examples of using web workers here - games, graphics, crypto. Another use is Web I/O - in other words, polling URLs in background. That way you don't block the UI waiting for polling results. Another practical use: in Bespin, they’re using Web Workers to do the syntax highlighting, which you wouldn’t want to block your code editing whilst you’re using the app. From Mozilla : One way workers are useful is to allow your code to perform processor-intensive calculations

how to send xmlhttprequest continuously in webworker?

旧城冷巷雨未停 提交于 2019-11-28 02:19:20
I am new to webworker but I managed to send xmlhttprequest to my rest api and I got json back. But I want send this request again and again (in a loop), until the page is active. I actually want to show values in real time. I want to make a simple web application in which when data is inserted in database my webworker should show that data without refreshing the page. Is there any better way to do so. Kindly help me in it. sorry for bad English. You can use EventSource to get stream from server until .close() is called at Worker , or message is passed to Worker signalling Worker to call .close

Is it possible to run Angular in a web worker?

百般思念 提交于 2019-11-28 01:19:58
问题 I am build a SPA app with angular and I would like to have my Angular service "WebService" shared with a web worker. The objective is to have one "WebService" shared so that I can use the same service in the background (in the web worker) and in the front-end (the angular app). Is this feasible ? Additional info: the idea here is for the synchronisation of data on the remote server, so you have the main app working with an "online|offline" mode, saving the data to the local web-storage and|or

Does a Firefox Workers limit exist?

一曲冷凌霜 提交于 2019-11-28 00:54:42
问题 Im trying to create web Workers and post messages to them in cycle: array.forEach(function (data) { this.createWorker(); this.workers[this.workersPointer].postMessage({task: 'someTask', data: string}); }, this); createWorker function: createWorker: function () { this.workersPointer++; var worker = this.workers[this.workersPointer] = new Worker('Worker.js'), storage = this; worker.onmessage = function (event) { if (event.data.error) { storage[event.data.task + 'Errback'](event.data.error); }