A portable and efficient implementation of a future in Delphi and FreePascal
A portable and efficient implementation of a future in Delphi and FreePascal version 1.32
Author: Amine Moulay Ramdane.
Description:
A "future" is an object that promises to provide a value sometime in the future. The value is computed in a background thread. When the application needs the value, it requests the value from the future--if the future isn't done, the application waits until the value is ready.
I have also added support for exceptions, so you have to know that programming with futures is asynchronous programming, but so that to be robust , the future implementation has to deal correctly with "exceptions", so in my implementation of a future when an exception is raised inside the future you will receive the exception, so i have implemented two things: The HasException() method so that to detect the exception from inside the future, and the exception and its address is returned as a string in the ExceptionStr property, and my implementation of a future does of course support passing parameters as a pointer to the future, also my implementation of a future works in Windows and Linux.
All the synchronization issues are hidden from the application.
Use the TFuture class by deriving a new class that overrides the Compute method.
I have provided you with a demo inside the zip file, please look at it inside testfuture.pas file.
You can go to download the zip files from:
https://drive.google.com/drive/folders/1GMEYVM1EIUDuD4I0PcYtZXyhg8Ig73zO?usp=sharing
Language: FPC Pascal v2.2.0+ / Delphi 5+: http://www.freepascal.org/
Required FPC switches: -O3 -Sd
-Sd for delphi mode....
Required Delphi XE-XE7 and Tokyo switch: -$H+ -DXE
You can configure it as follows from inside defines.inc file:
{$DEFINE CPU32} and {$DEFINE Windows32} for 32 bit systems
{$DEFINE CPU64} and {$DEFINE Windows64} for 64 bit systems
- Platform: Windows, Unix and Linux (x86)