Async/Await
The Async/Await
program from the code folder for this chapter demonstrates the use of the Async/Await pattern in OTL. It is practically identical to the PPL version from the last chapter’s code. This is not surprising, given that I had implemented the PPL version of Async/Await, mimicking the OTL version. The biggest change in the code was replacing the System.Threading
unit with OtlParallel
. The following code fragment shows the method that runs the LongTask
method in a background thread by using the OTL Async/Await:
procedure TfrmAsyncAwait.btnLongTaskAsyncClick( Sender: TObject); begin Log(Format('Button click in thread %d', [TThread.Current.ThreadID])); (Sender as TButton).Enabled := false; Async(LongTask) .Await( procedure begin Log(Format('Await in thread %d', ...