简体   繁体   English

setTimeout VS Web Worker-什么时候使用什么?

[英]setTimeout VS web worker - when to use what?

Both setTimeout and web worker more or less do the same thing. setTimeout和Web Worker或多或少都执行相同的操作。 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. 这就是Web Worker的工作。

setTimeout puts a function on a queue to be run later. setTimeout将函数放在队列中,以便稍后运行。 When it runs it still runs on the main thread and is just as blocking. 当它运行时,它仍在主线程上运行,就像阻塞一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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