Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2021-06

RES: Pas2js Digest, Vol 39, Issue 1

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Henrique Gottardi Werlang
Unit MyTest;
procedure Run; async;
begin
  // do something...
end;
begin
   run()._then(function (a : jsvalue) : jsvalue
     begin
     end);
end.

In the line "run()._then(function (a : jsvalue) : jsvalue” give me the error “Error: illegal qualifier "." after " run():Procedure/Function"”

De: <mailto:>
Enviado:terça-feira, 1 de junho de 2021 07:00
Para: <mailto:>
Assunto: Pas2js Digest, Vol 39, Issue 1

Send Pas2js mailing list submissions to

To subscribe or unsubscribe via the World Wide Web, visit https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freepascal.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fpas2js&amp;data=04%7C01%7C%7C993164b4dd5f46e3f56e08d924e407ad%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637581384059437072%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=CVena48XVFUyhZ5NC8ajTNY%2BQa8uyZIJuChX%2FCA3p2Q%3D&amp;reserved=0 or, via email, send a message with subject or body 'help' to

You can reach the person managing the list at

When replying, please edit your Subject line so it is more specific than "Re: Contents of Pas2js digest..."

Today's Topics:

1. Async procedure. (Henrique Gottardi Werlang)
2. Re: Async procedure. (Michael Van Canneyt)

----------------------------------------------------------------------

Message: 1
Date: Mon, 31 May 2021 18:18:34 +0000
From: Henrique Gottardi Werlang
To: ""
Subject: [Pas2js] Async procedure.
Message-ID:

Content-Type: text/plain; charset="windows-1252"

I'm making a remote request client and I had a problem.

I declared an asynchronous procedure, but it doesn't generate a promise.

This I can't register the "then” event.

Is it possible to modify this procedure behavior?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.freepascal.org%2Fpipermail%2Fpas2js%2Fattachments%2F20210531%2F05d3a71c%2Fattachment-0001.htm&amp;data=04%7C01%7C%7C993164b4dd5f46e3f56e08d924e407ad%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637581384059437072%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=%2Bwr%2BjFmCBrl8KBdOUlarJQrb4KLS9Qqk6R%2FOIxt9XMY%3D&amp;reserved=0>

------------------------------

Message: 2
Date: Mon, 31 May 2021 21:06:32 +0200 (CEST)
From: Michael Van Canneyt
To: pas2js discussions
Subject: Re: [Pas2js] Async procedure.
Message-ID: <alpine.DEB.2.22.394.2105312102530.1614564 at home> Content-Type: text/plain; charset="windows-1252"; Format="flowed"

Henrique Gottardi Werlang wrote 5 lines
I'm making a remote request client and I had a problem. I declared an asynchronous procedure, but it doesn't generate a promise. This I can't register the "then” event.

Works fine here:

uses JS;
function Run: word; async;
begin
   Result:=3;
end;
begin
   run()._then(function (a : jsvalue) : jsvalue
     begin
     end);
end.

or

uses JS;
function Run: word; async;
begin
   Result:=3;
end;
var
   p: TJSPromise;
begin
   p:=Run(); // calling directly without await() returns a TJSPromise!
   p._then(function (a : jsvalue) : jsvalue
     begin
     end);
end.

So what does not work for you ?

Michael.

------------------------------

Subject: Digest Footer

Reply by email

Michael Van Canneyt
to Henrique Gottardi Werlang
Henrique Gottardi Werlang wrote 14 lines
Unit MyTest; procedure Run; async; begin // do something... end; begin run()._then(function (a : jsvalue) : jsvalue begin end); end. In the line "run()._then(function (a : jsvalue) : jsvalue” give me the error “Error: illegal qualifier "." after " run():Procedure/Function"”

I don't think you can use a procedure, you must use a function.

Mattias will have to confirm.

Michael.

Reply by email

Wagner Landgraf
to Michael Van Canneyt
Show quoted text 19 lines
> Unit MyTest; > > procedure Run; async; > begin > // do something... > end; > > begin > run()._then(function (a : jsvalue) : jsvalue > begin > end); > end. > > In the line "run()._then(function (a : jsvalue) : jsvalue” give me the error “Error: illegal qualifier "." after " run():Procedure/Function"” I don't think you can use a procedure, you must use a function. Mattias will have to confirm.

Indeed, I had to create a function that return JSValue even for procedures that are not supposed to return anything:

function TXDataWebConnection.OpenAsync: JSValue; async;
begin
  Result := TJSPromise.new(
    procedure(resolve, reject: TJSPromiseResolver)
    begin
      DoConnect(
        procedure
        begin
          if Assigned(FOnConnect) then
            FOnConnect(Self);
          resolve(nil);
        end,
        procedure(Error: TXDataWebConnectionError)
        begin
          reject(EXDataWebConnectionException.Create(Error));
        end
      );
    end
  );
end;

Reply by email

Mattias Gaertner
to Michael Van Canneyt: I don't think you can use a procedure, you must use a function. Mattias will have to…
Show quoted text 22 lines
On Tue, 1 Jun 2021, Henrique Gottardi Werlang wrote: > Unit MyTest; > > procedure Run; async; > begin > // do something... > end; > > begin > run()._then(function (a : jsvalue) : jsvalue > begin > end); > end. > > In the line "run()._then(function (a : jsvalue) : jsvalue” give me > the error “Error: illegal qualifier "." after " > run():Procedure/Function"” I don't think you can use a procedure, you must use a function. Mattias will have to confirm.

Correct.

function Run: JSValue; async;

Mattias

Reply by email

Mattias Gaertner
to Wagner Landgraf: Indeed, I had to create a function that return JSValue even for procedures that are not…
Show quoted text 24 lines
[...] Indeed, I had to create a function that return JSValue even for procedures that are not supposed to return anything: function TXDataWebConnection.OpenAsync: JSValue; async; begin Result := TJSPromise.new( procedure(resolve, reject: TJSPromiseResolver) begin DoConnect( procedure begin if Assigned(FOnConnect) then FOnConnect(Self); resolve(nil); end, procedure(Error: TXDataWebConnectionError) begin reject(EXDataWebConnectionException.Create(Error)); end ); end ); end;

Why does this need an async?
Why not

function TXDataWebConnection.OpenAsync: TJSPromise;
begin
  Result := TJSPromise.new..

?

Mattias

Reply by email

Wagner Landgraf
to Mattias Gaertner
Show quoted text 33 lines
> [...] > Indeed, I had to create a function that return JSValue even for > procedures that are not supposed to return anything: > > function TXDataWebConnection.OpenAsync: JSValue; async; > begin > Result := TJSPromise.new( > procedure(resolve, reject: TJSPromiseResolver) > begin > DoConnect( > procedure > begin > if Assigned(FOnConnect) then > FOnConnect(Self); > resolve(nil); > end, > procedure(Error: TXDataWebConnectionError) > begin > reject(EXDataWebConnectionException.Create(Error)); > end > ); > end > ); > end; Why does this need an async? Why not function TXDataWebConnection.OpenAsync: TJSPromise; begin Result := TJSPromise.new.. ?

I don’t remember anymore, does it work fine with await? Maybe it has to do with some TMS Web Core tooling. -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20210601/c89c64e0/attachment.htm>

Reply by email