Page 1 of 1

async await ( preferably without callbacks )

Posted: Wed Sep 04, 2024 8:02 pm
by the.weavster
Is there a way of doing async await in SB?

Re: async await ( preferably without callbacks )

Posted: Wed Sep 04, 2024 10:15 pm
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.

Re: async await ( preferably without callbacks )

Posted: Thu Sep 05, 2024 12:15 pm
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.