Haxe JS: Web worker script creation?

107 views
Skip to first unread message

Cambiata

unread,
Mar 23, 2015, 6:19:04 AM3/23/15
to haxe...@googlegroups.com
What's the current best Haxe way of creating a worker script?

Found this gist by Clemos, but it's from 2012 and uses a separate extern for Worker class...

Jonas

Cambiata

unread,
Mar 23, 2015, 10:05:28 AM3/23/15
to haxe...@googlegroups.com
Sorry, forgot the link to Clemo's gist:
https://gist.github.com/clemos/4086201

Sven Bergström

unread,
Mar 24, 2015, 4:18:32 AM3/24/15
to haxe...@googlegroups.com
Workers on web are extremely sandboxed,
they don't have access to any scope at all (including any haxe code from the "parent" app, no window globals, nothing).

In other words, the workers on js MUST be isolated, there is no other way. 
The approach by clemos makes that pretty easy to do, and should still be relevant even today.

Cambiata

unread,
Mar 24, 2015, 5:39:27 AM3/24/15
to haxe...@googlegroups.com
Got a minimalistic example working based on David Mouton's code from this thread:
https://groups.google.com/d/msg/haxelang/id97u-SIGA0/snfI9hBJNkQJ

Anyone interested can find it here:
https://gist.github.com/cambiata/be0c2dc499da4be71151


Cambiata

unread,
Mar 24, 2015, 6:24:59 AM3/24/15
to haxe...@googlegroups.com
Thank you, Sven!

There's js.html.WorkerGlobalScope (js.html.WorkerContext in Haxe 3.1) that gives access to setInterval etc.
Doesn't seem to work, though. Tagged with /** @throws DOMError */ in the source code...


Reply all
Reply to author
Forward
0 new messages