JavaScript Web Worker-close()与Terminate() [英] JavaScript Web Worker - close() vs terminate()

查看:47
本文介绍了JavaScript Web Worker-close()与Terminate()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不完全了解Web Workers的close()与Terminate()方法之间的区别.我在这里已经阅读了说明,似乎在做同样的事情? http://www.w3.org/TR/workers/

I'm not totally understanding the difference between the close() vs terminate() methods for Web Workers. I've read the descriptions here and it seems to be doing the same thing?? http://www.w3.org/TR/workers/

我什么时候可以使用另一个?

When would I use one over the other?

推荐答案

close()方法在工作人员的作用域内可见. terminate()方法是辅助对象界面的一部分,可以从外部"调用.

The close() method is visible inside the worker's scope. The terminate() method is a part of the worker object's interface and can be called "from the outside".

如果您在主脚本中创建了一个工作程序,并希望从该脚本中停止它,则应在工作程序对象上调用 terminate().如果要从工作程序代码中停止工作程序(例如,作为对外部消息的响应),则应调用 close()方法.

If you create a worker in your main script and want to stop it from that script you should call the terminate() on the worker object. If you want to stop the worker from the worker code (for example as a response to an external message) you should call the close() method.

来源: https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Workers_API/Using_web_workers#Terminate_a_worker

这篇关于JavaScript Web Worker-close()与Terminate()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆