Asynchronous Statements
From The Oxygene Language Wiki
This is a Language topic
Feel free to add your notes to this topic below.
Asynchronous statements are a feature of Delphi Prism that makes it possible to execute one or more statements asynchronously from the method in which they are defined. Implementation depends on whether the PFX framework is referenced. If so, Async statements are run via the PFX framework as a task, else they are added to the .NET thread pool.
To define async statements, the async keyword can be added before the statement, for example:
async for i := 0 to 10 do begin ... end;
or
async begin ... end;
All locals/params used are copied at the point of the async statement, so changes are not passed back (the procedure could be done already).
When you need to wait until an asynchronous statement is done you can assign the result of the async statement into a variable. This will return a System.Action that will force the statement to run, or wait until it's finished:
var x := async for i:= 0 to 100 do begin ... end; ... x;
Area: Oxygene Language
Compiler version: Oxygene 5
Language Glossary — Keywords — Types — FAQ — How To