Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTimeout VS web worker - when to use what?

Both setTimeout and web worker more or less do the same thing. They make the main thread non-blocking and does it's work asynchronously in the background. How do we judge when to use what?

like image 594
Ayan Dalal Avatar asked Jul 04 '26 02:07

Ayan Dalal


1 Answers

They make the main thread non-blocking and does it's work asynchronously in the background.

No. They don't. That's what a Web Worker does.

setTimeout puts a function on a queue to be run later. When it runs it still runs on the main thread and is just as blocking.

like image 164
Quentin Avatar answered Jul 06 '26 14:07

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!