How to Create an Asynchronous Unit in Delphi


Defining a Unit to provide await functionality to your Delphi applications. Edijs Kolesnikovičs was kind enough to post this on linkedin, something I did not have thought about. Please look into my Medium article if you have a subscription.
How to use it
Async(procedure begin
{ Call long processing function/procedure }
YourUiBlockingProcedure();
end).Await(procedure begin
{ Do Something After Completion }
end);
Alternative with Delphi FMX
As an alternative we can also use a TThread to accomplish processing, such as a REST request, without blocking the main UI as shown in the code below.
This can be easily used within a procedure or function to wrap up a process heavy computation and update the UI accordingly without blocking the main thread.
References
Subscribe to my newsletter
Read articles from Alessandro directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Alessandro
Alessandro
I am a developer from the Greater Boston area, I have a M.S. in Computer Science and Engineering from the University of Connecticut, focused on Bayesian Networks and Bayesian Knowledge Bases. I have experience working on 3D laser scanners, motion platforms, DARPA projects, 3D simulations using the Unity game engine for robotics in synthetic environments (game generated and scanned), mobile development in both Android and iOS. My strengths are in rapid prototyping and taking an idea into a release candidate. The process is a winding road that takes a lot of time