IPdfCancellationToken = interface
function GetIsCancelled: Boolean;
procedure ThrowIfCancelled;
procedure RegisterCallback(const ACallback: TThreadMethod);
property IsCancelled: Boolean read GetIsCancelled;
end;
IPdfCancellationTokenSource = interface
function GetToken: IPdfCancellationToken;
procedure Cancel;
property Token: IPdfCancellationToken read GetToken;
end;
TPdfCancellationTokenSource = class(TInterfacedObject, IPdfCancellationTokenSource, IPdfCancellationToken)
class function New: IPdfCancellationTokenSource; static;
end;
TPdfFutureWorker<T> = function(const AToken: IPdfCancellationToken): T of object;
TPdfFutureReply<T> = procedure(const AResult: TPdfFutureResult<T>) of object;
TPdfFutureThread<T> = class(TThread)
constructor Create(const AWorker: TPdfFutureWorker<T>; const AReply: TPdfFutureReply<T>; const AToken: IPdfCancellationToken);
end;
TPdfFuture<T> = class
class procedure Run(const AWorker: TPdfFutureWorker<T>; const AReply: TPdfFutureReply<T>; const AToken: IPdfCancellationToken = nil); static;
end;
| Type | Description |
|---|---|
EPdfOperationCancelled | Raised by ThrowIfCancelled when a worker observes a cancellation request |
EPdfOperationCancelled.Create | Creates the standard cancellation exception message used by token-aware workers |
IPdfCancellationToken | Read-only worker-side token with IsCancelled, ThrowIfCancelled, and RegisterCallback |
IPdfCancellationTokenSource | Owner-side source with Token and Cancel |
TPdfCancellationTokenSource | Default source and token implementation; create one with TPdfCancellationTokenSource.New |
TPdfFutureStatus | Result state: pfsSuccess, pfsCancelled, or pfsFailure |
TPdfFutureResult<T> | Completion envelope with Value, Status, ErrorMessage, and IsSuccess / IsCancelled / IsFailure |
TPdfFutureWorker<T> | Method-pointer callback that receives a cancellation token and returns the background result |
TPdfFutureReply<T> | Method-pointer callback that receives the completed TPdfFutureResult<T> on the host callback path |
TPdfFutureThread<T> | Thread implementation exposed for generic compiler compatibility; applications should use TPdfFuture<T>.Run instead |
TPdfFuture<T> | Generic helper that runs a worker on a background thread and posts completion to the main thread |
PdfNoCancellationToken | Shared token that never cancels, useful when an API requires a token but the caller has no cancel UI |
FPdfAsync keeps long-running render, export, and batch-processing code responsive without tying the library to one UI framework
Workers receive only IPdfCancellationToken, so they can poll IsCancelled, call ThrowIfCancelled, or register one callback without owning the cancel source
TPdfFuture<T>.Run wraps a worker result in TPdfFutureResult<T> and reports success, cancellation, and failure through one completion path
var
CancelSource: IPdfCancellationTokenSource;
begin
CancelSource := TPdfCancellationTokenSource.New;
TPdfFuture<Integer>.Run(Worker, Completed, CancelSource.Token);
CancelSource.Cancel;
end;