Page 5 of 5
Async question
Posted: Thu Mar 02, 2023 11:00 am
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
Async question
Posted: Thu Mar 02, 2023 11:13 am
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
gives
Code: Select all
error XS9002: Parser: unexpected input '_'
Thank you again!
Wolfgang
Async question
Posted: Thu Mar 02, 2023 1:06 pm
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
Async question
Posted: Thu Mar 02, 2023 7:19 pm
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:
Thank you very much for all your assistance!
When my FTPS lib is ready, I will post a link to the sources here.
Wolfgang