Passing objects to a web worker

后端 未结 8 1063
心在旅途
心在旅途 2020-11-28 06:19

I\'m trying to pass an object to a web worker through the postMessage function.
This object is a square that has a couple of functions to draw himself on a canvas and so

8条回答
  •  醉梦人生
    2020-11-28 06:40

    There are a few reasons why the error that you mention could have been thrown, the reasons are listed here.

    When sending objects to web workers, the object is serialized, and later deserialized in the web worker if the object is a serializable object.

    This means that the methods for the objects you send to your web worker are not something that can be passed to the web worker (causing the error that you have run into), and you will need to provide the necessary methods/functions to the objects on the web worker's side of the environment, and make sure they are not part of the object that is passed to the web worker(s).

提交回复
热议问题