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?
Asked
Active
Viewed 359 times
1
-
Do you start the worker from JS or is this also Dart code? – Günter Zöchbauer Feb 20 '14 at 14:33
-
Either one. I want to avoid using isolates though – Zane Kaminski Feb 20 '14 at 15:09
-
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 Feb 20 '14 at 15:12
-
Is there a reason why you dont want to use isolates? They *are* WebWorkers. – Tom C Feb 27 '14 at 21:52
1 Answers
0
The Worker
class seems to support what you want.
- You can use
postMessage
to send messages to it - You can subscribe to
onMessage
to receive messages - You can use
terminate
to terminate it

Danny Tuppeny
- 40,147
- 24
- 151
- 275