Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to cause Web Workers to Sleep?

Tags:

Since web workers negate the disadvantages of paused execution in JavaScript, as they will not block UI, is there a reliable method to get them to Sleep?

Either for a designated time, or until they receive a message?

like image 977
Jivings Avatar asked Feb 11 '12 17:02

Jivings


People also ask

Do web workers run in background?

Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering with the user interface.

Do web workers have access to window?

Objects such as window, document and parent can't be accessed inside the web worker.

Can web workers fetch?

Comlink-fetch allows you to use Fetch in a web worker that is exposed through Comlink.


1 Answers

setTimeoutand setInterval are available to web workers. So if you want to 'wait' your code this may be the best solution.

like image 155
Sebastian Otto Avatar answered Sep 30 '22 19:09

Sebastian Otto