I have compiled some dart code to javascript, and I want to run this code within a webworker. I don't attempt to access the DOM or anything in the worker, so it should work fine. However, I cannot respond to the onmessage event or call postMessage. There just isn't anything in the dart class library that would let me do so. The official JS interop library is more or less useless to me, because it just generates script tags, and that won't work in a webworker. So how can I get dart2js to emit some JS that will allow me to use onmessage and postMessage? Or should I be using a different strategy?
1
votes
Do you start the worker from JS or is this also Dart code?
- Günter Zöchbauer
Either one. I want to avoid using isolates though
- Zane Kaminski
I still don't understand what you try to do. Can you please explain your setup a bit more (please extend your question instead of adding comments).
- Günter Zöchbauer
Is there a reason why you dont want to use isolates? They are WebWorkers.
- Tom C
1 Answers
0
votes
The Worker class seems to support what you want.
- You can use
postMessageto send messages to it - You can subscribe to
onMessageto receive messages - You can use
terminateto terminate it