advice in js promise handling in TMS Webcore

Hi,


i have an ASM block as follow ,

var _myJsonStr : string ;
begin
ASM
      db.open();  //i am using dexie.org indexeddb but i think any JS promise will have this requirement.
      db.app_conf.where("dbname").equals("v10c_demo_gotdata1").each(function(rec1){
          _myJsonStr = JSON.stringify( rec1 ) ;
          alert( _myJsonStr );  //this confirmed that it caught my object string 
      });
END:

//because of the ASYNC nature of the promise in JS, 
//i am unable to CATCH the value of the _myJsonStr in Delphi 

showmessage( _myJsonStr   ); //when Delphi execute this line, the above ASM block may not
//yet completed , so can any help or advice , how can i catch the result of the promise in
//the ASM / JS promise block and able to GET notified so i can continue to process the _myJsonStr ?

end ;

Typically, the promise calls a Pascal class method which in return triggers a class event from where the application code can known that something completed in the JavaScript code. 

I would like to understand how to implement this in detail. Initially I thought you refer to AsyncAwait operators but this is not available yet Async Await/Promise not implemented?.
Please give me additional reference to understand how to handle JS promise with TMS Web Core especially because I am also interested in dexie.org to work with IndexedDB.

Thanks in advance

At this moment you can use await and promises in ASM blocks, i.e. directly in JavaScript.
When pas2js v2.0 is released and we have updated TMS WEB Core with pas2js v2.0, you will be able to use it from Pascal code too.

Let me understand it. I suppose to work with Async/Await JS operator I need to build the whole implementation related to IndexedDB in pure JS. If I try to mix JS with Pascal implementation a Syntax error happens due to the absense of async in pas2js:

Uncaught SyntaxError: await is only valid in async function

function TSearchDBManager.ContainsStore( const AStoreName: string ): boolean; async; <-- Async/Await operator not available in pas2js yet
var
  LStoreList  : TStringArray;
  LIndex      : Integer;
begin
  Self.fSearchText  := AStoreName;

  asm
    const promise = await Dexie.getDatabaseNames();

    promise.then( values => {
      let i = 0;

      LStoreList.length = values.length;

      for (i = 0; i < values.length; i++) {
        LStoreList[ i ] = values[i];
      }
      } );
  end;

  result  := false;

  for LIndex := 0 to Length( LStoreList ) - 1 do
    begin
      if LStoreList[ LIndex ] = AStoreName then
        begin
          result  := true;
          break;
        end;
    end;
end;

If I can´t use Async/Await operator in TMS Web Core, how can I handle promises in Delphi implementation/classes like "TSearchDBManager"? Do I need to build a JS "TSearchDBManager" class implementation to work with promises?

Thanks in advance.

pas2js 1.4, used in TMS WEB Core v1.5.6.0 does not support this in Object Pascal, so in this version you need to do this in JavaScript.
As I suggested, this is supported in pas2js v2.0 and we released a beta of v1.6 with pas2js v2.0 integrated today.