简体   繁体   中英

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. There is no onload , onreade , onstatechange or anything of the sort.

I am looking for an alternative to thescript element onload event but for web-workers.

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.)

A workaround might be to fetch the code in advance and then initiate the worker from a blob URL.

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