class documentation

class OperationTaskCancellation(ABC):

View In Hierarchy

Indicates whether a a Nexus task has been cancelled during a sync operation or before an async operation has returned a token.

Nexus worker implementations are expected to provide an implementation that enables cooperative cancellation for both sync and async operation handlers.

Operation Handler implementations are expected to periodically check is_cancelled or use wait_until_cancelled / wait_until_cancelled_sync to cancel in flight work when appropriate.

Method cancellation_reason Provide additional context for the cancellation, if available.
Method is_cancelled Return True if the associated task has been cancelled.
Async Method wait_until_cancelled Await cancellation using async primitives. Nexus worker implementations may return True for is_cancelled before this method returns and therefore may cause a race condition if both are used in tandem.
Method wait_until_cancelled_sync Block until cancellation occurs or the optional timeout elapses. Nexus worker implementations may return True for is_cancelled before this method returns and therefore may cause a race condition if both are used in tandem.
@abstractmethod
def cancellation_reason(self) -> str | None:

Provide additional context for the cancellation, if available.

@abstractmethod
def is_cancelled(self) -> bool:

Return True if the associated task has been cancelled.

@abstractmethod
async def wait_until_cancelled(self):

Await cancellation using async primitives. Nexus worker implementations may return True for is_cancelled before this method returns and therefore may cause a race condition if both are used in tandem.

@abstractmethod
def wait_until_cancelled_sync(self, timeout: float | None = None) -> bool:

Block until cancellation occurs or the optional timeout elapses. Nexus worker implementations may return True for is_cancelled before this method returns and therefore may cause a race condition if both are used in tandem.