Page 1 of 2

Procedure freezes open window

Posted: Wed Jun 20, 2018 4:11 pm
by Jarlve
Hey all,

Some of the procedures in my program can take a very long time to return. Is it possible to thread a procedure? Or to let it run in the background while the open window is still responsive?

Thanks.

Re: Procedure freezes open window

Posted: Wed Jun 20, 2018 9:46 pm
by the.weavster
You could take a look at Web Workers

Re: Procedure freezes open window

Posted: Thu Jun 21, 2018 2:30 pm
by Jarlve
Thanks the.weavster for the link.

Is there no way to do this in SpiderBasic?

Re: Procedure freezes open window

Posted: Thu Jun 21, 2018 3:04 pm
by Peter
Jarlve wrote:Is there no way to do this in SpiderBasic?
currently you cannot do this with the native SpiderBasic commands.

But if you have a web server that can run your own cgi programs, then there is the possibility to use SpiderBite.

Greetings ... Peter

Re: Procedure freezes open window

Posted: Thu Jun 21, 2018 3:30 pm
by Jarlve
Thanks Peter.

This should be possible out of the box.

Will use AddWindowTimer to let my procedure run periodically.

Re: Procedure freezes open window

Posted: Thu Jun 21, 2018 6:01 pm
by the.weavster
Jarlve wrote:Is there no way to do this in SpiderBasic?
I haven't tried it but it seems to me it should only be a matter of putting some JavaScript code in an EnableJS .. DisableJS block (which can be within a SB procedure).

Edit...
The worker file itself would probably have to be in JS.

Re: Procedure freezes open window

Posted: Thu Jun 21, 2018 6:34 pm
by Peter
the.weavster wrote:Edit...
The worker file itself would probably have to be in JS.
yes, and that is the main problem.

You would have to write a Postprocessor that cuts the corresponding Procedure from the generated js-file after compiling by SpiderBasic and saves it as a separate WebWorker file.

Greetings ... Peter

Re: Procedure freezes open window

Posted: Fri Jun 22, 2018 6:31 am
by the.weavster
Hi Peter
Peter wrote:You would have to write a Postprocessor that cuts the corresponding Procedure from the generated js-file after compiling by SpiderBasic and saves it as a separate WebWorker file.
But the WebWorker file is already separate:

worker.js

Code: Select all

onmessage = function(e) {
  var workerResult = 'Hello, ' + e.data[0] + " " + e.data[1] + "!";
  postMessage(workerResult);
}
worker.sb

Code: Select all

Procedure WorkerResponse(e)
  rsp.s = ""
  !v_rsp = v_e.data;
  Debug rsp
EndProcedure

Procedure HelloWorker(firstname.s,surname.s)
  EnableJS
  var myWorker = new Worker('worker.js');
  myWorker.onmessage = f_workerresponse;
  myWorker.postMessage([v_firstname,v_surname]);
  DisableJS
EndProcedure

HelloWorker("The","Weavster")

Re: Procedure freezes open window

Posted: Fri Jun 22, 2018 7:20 am
by Peter
the.weavster wrote:But the WebWorker file is already separate:
I assume that Jarlve wants to write his time-consuming Procedure in SpiderBasic-Syntax and not in JavaScript.

Greetings ... Peter

Re: Procedure freezes open window

Posted: Fri Jun 22, 2018 8:45 am
by the.weavster
I think while SB is in its early stages it will be very hard to avoid JS completely, it's probably better to embrace it and get used to combining the two.
For me at least the big bonus from using SB is avoiding HTML and CSS rather than avoiding JS :)