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

by Jarlve Wed Jun 20, 2018 4:11 pm

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: 136
Joined: Sat Mar 01, 2014 3:02 pm

Re: Procedure freezes open window

by the.weavster Wed Jun 20, 2018 9:46 pm

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

Re: Procedure freezes open window

by Jarlve Thu Jun 21, 2018 2:30 pm

Thanks the.weavster for the link.

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

Re: Procedure freezes open window

by Peter Thu Jun 21, 2018 3:04 pm

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

by Jarlve Thu Jun 21, 2018 3:30 pm

Thanks Peter.

This should be possible out of the box.

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

Re: Procedure freezes open window

by the.weavster Thu Jun 21, 2018 6:01 pm

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: 553
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Procedure freezes open window

by Peter Thu Jun 21, 2018 6:34 pm

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: 136
Joined: Sat Mar 01, 2014 3:02 pm

Re: Procedure freezes open window

by the.weavster Fri Jun 22, 2018 6:31 am

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: 553
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Procedure freezes open window

by Peter Fri Jun 22, 2018 7:20 am

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: 136
Joined: Sat Mar 01, 2014 3:02 pm

Re: Procedure freezes open window

by the.weavster Fri Jun 22, 2018 8:45 am

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 :)
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 1 guest