[Pas2js] RES: Pas2js Digest, Vol 39, Issue 2

Henrique Gottardi Werlang henriquewerlang at hotmail.com
Tue Jun 1 14:15:32 CEST 2021


Thanks for the replys!

I suggested this because I'm implementing an API in Delphi. And in Delphi there is nothing equivalent to JSValue. Of course, you could declare any type with that name, to return, but it's not the idea, because the client and server share the same unit that has the contract interface.

And in this interface there is a procedure that does something, which can take time to finish.

So on the client side I need this to return a promise, so the browser doesn't get stuck.

I made a change to the local fonts I have from the compiler, that when the procedure is asynchronous, I make the procedure return a promise.

Of course this in a way violates pascal's concepts, but it got a lot better the implementations made, with this happening.

I'm not going to record any assignments regarding that, unless you think that's interesting.

De: pas2js-request at lists.freepascal.org<mailto:pas2js-request at lists.freepascal.org>
Enviado:terça-feira, 1 de junho de 2021 08:34
Para: pas2js at lists.freepascal.org<mailto:pas2js at lists.freepascal.org>
Assunto: Pas2js Digest, Vol 39, Issue 2

Send Pas2js mailing list submissions to
        pas2js at lists.freepascal.org

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&data=04%7C01%7C%7Cb70fc2dc548144f7f77408d924f12a9e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637581440485925406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=k2KdbYS2pZ8iFxyrdneatAfY%2BUOqqlSYwTDXYv7VYE4%3D&reserved=0
or, via email, send a message with subject or body 'help' to
        pas2js-request at lists.freepascal.org

You can reach the person managing the list at
        pas2js-owner at lists.freepascal.org

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


Today's Topics:

   1. RES: Pas2js Digest, Vol 39, Issue 1 (Henrique Gottardi Werlang)
   2. Re: RES: Pas2js Digest, Vol 39, Issue 1 (Michael Van Canneyt)
   3. Re: RES: Pas2js Digest, Vol 39, Issue 1 (Wagner Landgraf)
   4. Re: RES: Pas2js Digest, Vol 39, Issue 1 (Mattias Gaertner)


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

Message: 1
Date: Tue, 1 Jun 2021 10:33:08 +0000
From: Henrique Gottardi Werlang <henriquewerlang at hotmail.com>
To: "pas2js at lists.freepascal.org" <pas2js at lists.freepascal.org>
Subject: [Pas2js] RES: Pas2js Digest, Vol 39, Issue 1
Message-ID:
        <CP4P284MB09943FB37FB51F2D88432CF4B23E9 at CP4P284MB0994.BRAP284.PROD.OUTLOOK.COM>

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

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: pas2js-request at lists.freepascal.org<mailto:pas2js-request at lists.freepascal.org>
Enviado:terça-feira, 1 de junho de 2021 07:00
Para: pas2js at lists.freepascal.org<mailto:pas2js at lists.freepascal.org>
Assunto: Pas2js Digest, Vol 39, Issue 1

Send Pas2js mailing list submissions to
        pas2js at lists.freepascal.org

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&data=04%7C01%7C%7Cb70fc2dc548144f7f77408d924f12a9e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637581440485925406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=k2KdbYS2pZ8iFxyrdneatAfY%2BUOqqlSYwTDXYv7VYE4%3D&reserved=0
or, via email, send a message with subject or body 'help' to
        pas2js-request at lists.freepascal.org

You can reach the person managing the list at
        pas2js-owner at lists.freepascal.org

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 <henriquewerlang at hotmail.com>
To: "pas2js at lists.freepascal.org" <pas2js at lists.freepascal.org>
Subject: [Pas2js] Async procedure.
Message-ID:
        <CP4P284MB0994AF032625620A0E1D1FD2B23F9 at CP4P284MB0994.BRAP284.PROD.OUTLOOK.COM>

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&data=04%7C01%7C%7Cb70fc2dc548144f7f77408d924f12a9e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637581440485925406%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=IHXivkgU%2BCOp2lp5hFbwuS5sFO8DuJidF47L%2BFMZl54%3D&reserved=0>

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

Message: 2
Date: Mon, 31 May 2021 21:06:32 +0200 (CEST)
From: Michael Van Canneyt <michael at freepascal.org>
To: pas2js discussions <pas2js at lists.freepascal.org>
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"



On Mon, 31 May 2021, Henrique Gottardi Werlang wrote:

> 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

_______________________________________________
Pas2js maillist  -  Pas2js at lists.freepascal.org
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freepascal.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fpas2js&data=04%7C01%7C%7Cb70fc2dc548144f7f77408d924f12a9e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637581440485935387%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=wAkv7CB7Fi7dd0KlMFdh0dP4O16ykVOqqB8%2FvzpQsQo%3D&reserved=0


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

End of Pas2js Digest, Vol 39, Issue 1
*************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.freepascal.org%2Fpipermail%2Fpas2js%2Fattachments%2F20210601%2F0dc77c80%2Fattachment-0001.htm&data=04%7C01%7C%7Cb70fc2dc548144f7f77408d924f12a9e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637581440485935387%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=SK5kyb5uAU3ljuOJ%2FM8WbN2UojY%2FWtbM5k%2BM2l1aMR8%3D&reserved=0>

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

Message: 2
Date: Tue, 1 Jun 2021 13:18:44 +0200 (CEST)
From: Michael Van Canneyt <michael at freepascal.org>
To: pas2js discussions <pas2js at lists.freepascal.org>
Subject: Re: [Pas2js] RES: Pas2js Digest, Vol 39, Issue 1
Message-ID: <alpine.DEB.2.22.394.2106011318110.1635063 at home>
Content-Type: text/plain; charset="windows-1252"; Format="flowed"



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.

Michael.

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

Message: 3
Date: Tue, 1 Jun 2021 08:24:01 -0300
From: Wagner Landgraf <wagner at tmssoftware.com>
To: pas2js discussions <pas2js at lists.freepascal.org>
Subject: Re: [Pas2js] RES: Pas2js Digest, Vol 39, Issue 1
Message-ID: <FFEF784C-869E-44CD-A3FA-772BDE63BE26 at tmssoftware.com>
Content-Type: text/plain;       charset=utf-8


>
>> 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;





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

Message: 4
Date: Tue, 1 Jun 2021 13:25:27 +0200
From: Mattias Gaertner <nc-gaertnma at netcologne.de>
To: pas2js at lists.freepascal.org
Subject: Re: [Pas2js] RES: Pas2js Digest, Vol 39, Issue 1
Message-ID: <20210601132527.66f7af9e at limapholos.matflo.wg>
Content-Type: text/plain; charset=UTF-8

On Tue, 1 Jun 2021 13:18:44 +0200 (CEST)
Michael Van Canneyt <michael at freepascal.org> wrote:

> 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


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

Subject: Digest Footer

_______________________________________________
Pas2js maillist  -  Pas2js at lists.freepascal.org
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freepascal.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fpas2js&data=04%7C01%7C%7Cb70fc2dc548144f7f77408d924f12a9e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637581440485935387%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=wAkv7CB7Fi7dd0KlMFdh0dP4O16ykVOqqB8%2FvzpQsQo%3D&reserved=0


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

End of Pas2js Digest, Vol 39, Issue 2
*************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20210601/a514ebc3/attachment-0001.htm>


More information about the Pas2js mailing list