Skip to content

Commit

Permalink
Added WaitFor method on token interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentparrett committed Sep 11, 2023
1 parent 507f791 commit 6cf45a6
Show file tree
Hide file tree
Showing 4 changed files with 675 additions and 136 deletions.
6 changes: 6 additions & 0 deletions Source/VSoft.CancellationToken.Impl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ TCancellationToken = class(TCancellationTokenBase, ICancellationToken, ICancel
function GetEvent : TEvent;virtual;
{$ENDIF}
function IsCancelled: boolean;virtual;
function WaitFor(Timeout: Cardinal): TWaitResult;virtual;
procedure Cancel;virtual;
procedure Reset;virtual;
public
Expand Down Expand Up @@ -102,4 +103,9 @@ procedure TCancellationToken.Reset;
end;


function TCancellationToken.WaitFor(Timeout: Cardinal): TWaitResult;
begin
result := FEvent.WaitFor(Timeout);
end;

end.
5 changes: 4 additions & 1 deletion Source/VSoft.CancellationToken.pas
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ interface
System.SyncObjs;

type
//TDODO : use system.types if available.
TWaitResult = System.SyncObjs.TWaitResult;

/// ICancellationToken is passed to async methods
/// so that they can determin if the caller has
/// cancelled.
Expand All @@ -44,7 +47,7 @@ interface
function GetEvent : TEvent;
{$ENDIF}
function IsCancelled: boolean;

function WaitFor(Timeout: Cardinal): TWaitResult;
{$IFDEF MSWINDOWS}
//Note : do not call SetEvent on this handle
//as it will result in IsSignalled prop
Expand Down
Loading

0 comments on commit 6cf45a6

Please sign in to comment.