class Cancel < Exception

Inherits from
Exception

Raised when a task is explicitly cancelled.

Nested Classes and Modules

class Cause

Represents the source of the cancel operation.

class Later

Used to defer cancelling the current task until later.

Definitions

def initialize(message = "Task was cancelled")

Create a new cancel operation.

This is a compatibility method for Ruby versions before 3.5 where cause is not propagated correctly when using Fiber#raise

Signature

parameter message String | Hash

The error message or a hash containing the cause.

Implementation

def initialize(message = "Task was cancelled")
	
	if message.is_a?(Hash)
		@cause = message[:cause]
		message = "Task was cancelled"
	end
	
	super(message)
end

def cause

This is a compatibility method for Ruby versions before 3.5 where cause is not propagated correctly when using Fiber#raise, we explicitly capture the cause here.

Signature

returns Exception

The cause of the cancel operation.

Implementation

def cause
	super || @cause
end