简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM