Future
The OTL version of the Future pattern looks very similar to the PPL version but is slightly more powerful, as it implements its own notification mechanism to signal task completion. The basic version, however, is almost the same as the PPL version (the only difference is using Parallel.Future
instead of TParallel.Future
):
procedure TfrmFuture.btnFutureClick(Sender: TObject); begin FFuture := Parallel.Future<integer>(CountPrimes); end;
The main difference between the OTL and PPL implementations lies in how the code can notify the main thread of the completion of the calculation. In PPL, we used TThread.Queue
inside the background calculation code. OTL solves this with a task configuration block.
This approach, which is used in many OTL parallel patterns, allows the code to pass a special IOmniTaskConfig
parameter to the future (or other parallel) pattern. This interface can be used to configure a cancellation mechanism, set up a thread pool to be used...