简体   繁体   English

在不发送显式消息的情况下检测到网络工作者已被加载

[英]Detecting that a web-worker has been loaded without sending an explicit message

Is there a way to detect that a web-worker has been loaded.有没有办法检测到网络工作者已被加载。 I looked at the spec but there is only an error event.我查看了规范,但只有一个error事件。 There is no onload , onreade , onstatechange or anything of the sort.没有onloadonreadeonstatechange或任何类似的东西。

I am looking for an alternative to thescript element onload event but for web-workers.我正在寻找脚本元素 onload事件的替代方案,但适用于网络工作者。

I want to do it without the worker explicitly sending a message after load because it is for a library, and I need it to be as general as possible and don't want to impose this restriction on the worker.我想在没有工作人员在加载后明确发送消息的情况下执行此操作,因为它是针对库的,并且我需要它尽可能通用并且不想对工作人员施加此限制。

There is not by design.设计上没有。 This was planned originally , but got taken out later on. 本来是这么计划的,后来被拿掉了。 I forgot the rationale, but I suspect it is related to certain implementations allowing the allocation of many workers, but only running a couple at the time.我忘记了基本原理,但我怀疑这与某些允许分配许多工人但当时只运行几个工人的实现有关。

(There are some plans to improve this, in particular if SharedArrayBuffer happens, which needs that kind of information, but there's no standard way now.) (有一些计划来改进这一点,特别是如果SharedArrayBuffer发生,它需要那种信息,但现在没有标准的方法。)

A workaround might be to fetch the code in advance and then initiate the worker from a blob URL.一种解决方法可能是提前获取代码,然后从 blob URL 启动工作程序。

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

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