Is it possible to pass a callback to a webworker?

Viewed 4081

I have a render worker that I would like to pass a callback to. I know that the worker.postMessage method now supports Javascript Objects, but when I try to pass a function withing the object I get an error telling me that it "couldn't clone" the object.

I also tried JSON.stringify() on the object, and learned that functions don't get stringified because JSON doesn't support function scope.

Is there a way to pass a callback to a Web Worker? If not, how would you suggest working around the limitation?

My issue is that I send the worker a message to start the rendering at the same time I start an animation. So I need to wait until BOTH are finished before executing the "callback"

1 Answers
Related