Procedure freezes open window

Just starting out? Need help? Post your questions and find answers here.
Jarlve
Posts: 19
Joined: Mon Jun 18, 2018 6:10 pm

Procedure freezes open window

Post 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.
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: Procedure freezes open window

Post by the.weavster »

You could take a look at Web Workers
Jarlve
Posts: 19
Joined: Mon Jun 18, 2018 6:10 pm

Re: Procedure freezes open window

Post by Jarlve »

Thanks the.weavster for the link.

Is there no way to do this in SpiderBasic?
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Procedure freezes open window

Post 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
Jarlve
Posts: 19
Joined: Mon Jun 18, 2018 6:10 pm

Re: Procedure freezes open window

Post by Jarlve »

Thanks Peter.

This should be possible out of the box.

Will use AddWindowTimer to let my procedure run periodically.
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: Procedure freezes open window

Post 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.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Procedure freezes open window

Post 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
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: Procedure freezes open window

Post 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")
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Procedure freezes open window

Post 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
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: Procedure freezes open window

Post 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 :)
Post Reply