I created a class derived from TThread
that executes in background a query.
I want that this class is decoupled from the client.
This kind of th
Using OmniThreadLibrary:
uses OtlFutures;
var
thread: IOmniFuture;
thread := TOmniFuture.Create(
function: integer;
begin
Result := YourFunction;
end;
);
// do something else
threadRes := thread.Value; //will block if thread is not yet done
Creating the TOmniFuture object will automatically start background thread executing your code. Later you can wait on result by calling .Value or you can use .TryValue or .IsDone to check if the thread has already completed its work.