Table of Contents

CancellationToken

Namespace
ZCore
Extends
Inherited Properties
Inherited Methods
Implements

This object is an extension to StartToken to support cancellation requests. Use it to issue Async methods for objects, which support halting.

(...)
VAR_INST
  cancellationObject : ZCore.CancellationToken;
  sequence : ZCore.Sequence;
END_VAR
(...)
cancellationObject.Recover();
sequence.RunAsync(cancellationObject);

IF NOT cancellationObject.Error
THEN
  cancellationObject.Halt(); // use this call to issue a halt command
END_IF

An object, which was halted can be resumed using the Resume method.

FUNCTION_BLOCK CancellationToken EXTENDS ZCore.StartToken IMPLEMENTS ZCore.ICancellationToken, ZCore.IStartToken, ZCore.IHaltToken, ZCore.IError, ZCore.IObject, ZCore.IRecoverable

Properties

HaltRequested

Indicates that any holder of this token should try to halt its process as soon as possible and transition to the Idle state.

PROPERTY HaltRequested : BOOL

Property Value

BOOL

ResumeRequested

Indicates that any holder of this token should resume its process after a halt occured and subsequently Resume was issued.

PROPERTY ResumeRequested : BOOL

Property Value

BOOL

Methods

Halt

Issue a halt request to all object carrying this token.

METHOD Halt ()

Recover

Set the internal error state to false. This is useful after the Abort method was called and error handling can recover from this error. It is mainly used to recover Tokens as seen in the following example.

(...)
VAR_INST
  startToken : ZCore.StartToken;
END_VAR
(...)
startToken.Recover();
RunActionAsync(startToken);
IF NOT startToken.Error
THEN
  (...)
END_IF

Recovering a CancellationToken also resets the halt requested and resume requested flag

METHOD Recover ()

Resume

Issue a resume request to all object carrying this token. A resume can only be issued if the token is not in an error state and a halt was previously requested using the Halt method. Calling this method will automatically also Recover the token from potential errors (but of course keep the requested resume flag intact)

METHOD Resume ()