async await ( preferably without callbacks )

Just starting out? Need help? Post your questions and find answers here.
the.weavster
Posts: 229
Joined: Sat Mar 01, 2014 3:02 pm

async await ( preferably without callbacks )

Post by the.weavster »

Is there a way of doing async await in SB?
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: async await ( preferably without callbacks )

Post by Peter »

Code: Select all

Procedure.s HTTPRequestSync(Type, URL.s, Parameters.s = "") 
  
  ! let type;
  
  ! switch (v_type) {
  !   case 0: type = "GET"; break;
  !   case 1: type = "POST"; break;
  !   case 2: type = "PUT"; break;
  !   case 4: type = "DELETE"; break;
  !   case 3: type = "PATCH"; break;
  ! }
  
  ! const result = $.ajax({
  !   url: v_url,
  !   type: type,
  !   data: v_parameters,
  !   async: false,
  !   dataType: 'json',
  ! });
  
  ! return result.responseText;
  
EndProcedure

Define Result.s

Debug "Starting"
Result = HTTPRequestSync(#PB_HTTP_Get, #PB_Compiler_Filename)
Debug "Len(Result): " + Str(Len(Result))
Debug "Finished"
Remark: "async: false" is not the best but the easiest solution.
the.weavster
Posts: 229
Joined: Sat Mar 01, 2014 3:02 pm

Re: async await ( preferably without callbacks )

Post by the.weavster »

Let's say I want to run a SB app in a PB WebViewGadget that exposes custom PB functions, those would return a promise.
Post Reply