Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set a Web Worker to low priority?

I am thinking of using Web Workers to provide some background functionality while a user is browsing my website (that's what Web Workers are for, right?). However, I don't want to take the risk of compromising the user experience by causing laggy scrolling, unresponsive controls, etc. Web Workers are mapped on OS threads, hence I would expect some control on the priority of these threads however, as far as I know, there's no such thing in the current API. Do you know a how to accomplish this? Even with a hack?

like image 592
tunnuz Avatar asked Dec 29 '11 14:12

tunnuz


People also ask

Are web workers multithreaded?

Developers have been solving this problem in desktop applications for a long time with multithreading. Web Workers bring multithreading to JavaScript web applications. Different parts of code can run simultaneously without blocking each other and communicate using message passing techniques.

Can Webworkers access DOM?

Web workers can't access DOM elements from the web page. Web workers can't access global variables and JavaScript functions from the web page. Web workers can't call alert() or confirm() functions. Objects such as window, document and parent can't be accessed inside the web worker.

How many web workers can run concurrently?

A web worker is a JavaScript program running on a different thread, in parallel with main thread. The browser creates one thread per tab. The main thread can spawn an unlimited number of web workers, until the user's system resources are fully consumed.

How do I know if WebWorker is running?

Show activity on this post. You should have the web worker post messages about events, like when it is finished work, this way the parent can listen to these messages/events and know when work has completed. The web worker can even post progress events, this is all up to you to build though, it does not come included.


1 Answers

Well, there's no API call to control low-level details like this. However, I think you should first implement what you want to do and then test if the performance hit is too great on the user experience. I'm assuming that since they did not add fine control over how the threads execute, they're probably well managed by the underlying implementation.

like image 52
Tudor Avatar answered Sep 22 '22 16:09

Tudor