Monday, October 5, 2020

Re: Is it possible to implement a web worker with GWT?

Thank you both for your inputs.

Yes the gwt-worker is the linker I was looking for :)

However the produced JS file breaks because it still contains some references to the window object which doesn't exist in the context of a web worker.

Is there an option in the GWT compiler to tell that the context is a web worker and that it should not use such objects but "self" instead?

Otherwise I noticed the linker already produces some patch code before calling GWT, the first JS line looks like this:
$stats=function(){};$self=self;$wnd=self;$doc=self;$sessionId=null; etc...

Manually adding window=self; in that line actually solves the JS break issue.

In the probable case GWT has not been designed for web workers and we can't prevent it producing code without refering to window, I will open an issue in the gwt-worker linker repository to ask adding window=self; in the patch line. 


On Friday, 2 October 2020 at 17:14:03 UTC+1 lofid...@gmail.com wrote:
I'm not sure, will this project helps you: https://gitlab.com/ManfredTremmel/gwt-webworker?

t.br...@gmail.com schrieb am Freitag, 2. Oktober 2020 um 17:04:55 UTC+2:
It is, through a linker: http://www.gwtproject.org/doc/latest/DevGuideLinkers.html
It might work with the D8ScriptLinker shipped in GWT (https://github.com/gwtproject/gwt/blob/2.9.0/dev/core/src/com/google/gwt/core/linker/D8ScriptLinker.java); you'll have to declare it in a *.gwt.xml though (define-linker then add-linker).
Or there might be (IIRC, there are) libraries with such a linker specifically for workers.


On Thursday, October 1, 2020 at 10:43:37 PM UTC+2, Bruno Salmon wrote:
hi,

I have a GWT web app that I would like to make more reactive by moving some heavy computation code into web workers. This code doesn't need the context of the application to run, I just need to pass it a few input parameters so it should be a good fit for a web worker.

I see how the web app can instantiate web workers using elemental2.dom.Worker.

But as my worker code is in Java, I would like to know if I can use the GWT compiler to generate the worker itself. I expect a js file with a onmessage function as output that I can load from the web app.

Is it possible to do this?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/26a5afff-b155-4c03-9825-451a0c92d463n%40googlegroups.com.

No comments:

Post a Comment