Web workers

240 views
Skip to first unread message

Harold Comere

unread,
Sep 8, 2012, 3:58:07 PM9/8/12
to google-we...@googlegroups.com
Hi all,

Does anyone have used web workers via GWT ?

I have tried to use web workers looking at speed tracer code :
But i did not succeed to launch my worker.

Is there any example anywhere ?

Regards,
Harold

Derek

unread,
Sep 9, 2012, 11:24:44 AM9/9/12
to google-we...@googlegroups.com
I've played around with web workers on GWT, but it's not a lot of fun. You can't use normal GWT devmode on them (though maybe superdevmode would work?). So you essentially have to write the worker, compile it, and then call it from your non-worker code and hope it does what you want.

Harold Comere

unread,
Sep 10, 2012, 3:58:50 AM9/10/12
to google-we...@googlegroups.com
Hi Derek,

As i have a lot of JSNI calls, i do not use the dev mode.
Super dev mode is far more suitable !

Btw, i still have issue with my worker because after GWT compilation, the generated script contains "window" and "document" variables which are not defined in the worker scope, so i get an error at worker start.

 function myworker(){
 ...
var $wnd = window, $doc = document ...
...

How do you say to GWT to ignore "window" things ?
I have read that we should use $self instead of $window but i do not know how to configure GWT compiler.

Regards,
Harold


2012/9/9 Derek <derek...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/C4M07sUMoFsJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Small WebGL 3D engine for GWT
http://code.google.com/p/ethereal-engine/

Derek

unread,
Sep 10, 2012, 9:58:49 AM9/10/12
to google-we...@googlegroups.com
I'd need to look at my code again (not convenient to do right now), but I recall putting something along the lines of 'var $wnd = $self' at the top of the js wrapper. (i.e., editing the speedtracer code's javascript file and adding those lines to the top)

Harold Comere

unread,
Sep 13, 2012, 5:15:00 AM9/13/12
to google-we...@googlegroups.com
Hi Derek,

Thanks for the advice.
I tried to put "var $wnd= $self" but what about "var $document" ?

if you have some time to check your code, it is welcome :)

Regards,
Harold

2012/9/10 Derek <derek...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Derek

unread,
Sep 13, 2012, 10:18:58 AM9/13/12
to google-we...@googlegroups.com
Okay, I've looked at my code.

I modified the DedicatedWorkerTemplate.js file from speedtracer to include the following lines near the top (first two should already be there):

$self = self;
$sessionId = null;
$wnd = self;
$doc = self;
window = self;

This kept a lot of the code I was using that was looking for a $wnd and $doc variable happy. Of course, it doesn't *actually* provide window or document objects, it just renames them so the code doesn't blow up. This has been part of the problem with the project I've been working on, I'm using an external library that is unaware it is being used as a worker and while in theory it's just doing processing, it's still expecting to find certain values in window and document objects, so I've been slowly and annoyingly figuring out how to create a mock window and document object to accommodate the code. But it's a pain and I'm considering just rewriting it. Unfortunately that removes the usefulness of the library since I was using it to save me from coding my own implementation (and I'd have to keep porting over the updates as they occur, bleh). On the other hand, running the third-party processing in the main thread really kills the app's performance (especially on mobile).

Sigh. Apparently I needed to vent... Sorry about that.

Derek
Harold

2012/9/10 Derek <derek...@gmail.com>
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Harold Comere

unread,
Sep 13, 2012, 11:26:10 AM9/13/12
to google-we...@googlegroups.com
Hi again,

Your problematic should give headache :-p
In this case i always choose to rewrite the library by myself. I think this saves lot of time in the long term.

Btw, I have modified the  DedicatedWorkerTemplate.js as you wrote but this does not make any change to the generated worker script after compilation. 
I think i have missed anything while extracting the webworker part of speedtracer...

Is it possible that you send to me the webworker part of your project ? 
I have hard time trying to understand all this dedicated linker stuff :-p

Regards,
Harold



Reply all
Reply to author
Forward
0 new messages