Async question

This forum is meant for questions and discussions about the X# language and tools
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Async question

Post by robert »

Wolfgang,
We also accept the discard name '_' in our code.
Did you try

Code: Select all

self:Post( { _ => self:done := true }, null )
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Async question

Post by wriedmann »

Hi Robert,
ok, thank you very much, that works.
But how do I add an async keyword to a lamda expression?

Code: Select all

synch.Post(async _ =>
            {
                try
                {
                    await task();
                }
                catch (Exception e)
                {
                    synch.InnerException = e;
                    throw;
                }
                finally
                {
                    synch.EndMessageLoop();
                }
            }, null);
does not works as

Code: Select all

	synch:Post( { _ =>
	    try
        await task()
	    catch e as Exception
        synch.InnerException := e
        throw
	    finally
        synch:EndMessageLoop()
	    end try
	}, null )
and adding the async before the underscore like

Code: Select all

	synch:Post( { async _ =>
	    try
gives

Code: Select all

error XS9002: Parser: unexpected input '_'
Thank you again!
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Async question

Post by robert »

Wolfgang,

Change the lambda to a delegate

Code: Select all

synch:Post(  async delegate(_ as object)  { 
	try
           await task()
	catch e as Exception
            synch.InnerException := e
             throw
	finally
            synch:EndMessageLoop()
	 end try
	}, null )
Note I did not test this since I do not have all the code

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Async question

Post by wriedmann »

Hi Robert,
thank you very much, my code compiles now without error.And it works also <g>.I have attached the entire prg file here if someone other needs it:
AsyncHelpers.zip
(1.29 KiB) Downloaded 89 times
Thank you very much for all your assistance!
When my FTPS lib is ready, I will post a link to the sources here.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply