Async::SafeSourceAsyncSafeViolationError

class ViolationError

Raised when an object is accessed from a different fiber than the one that owns it.

Definitions

def initialize(message = nil, target:, method:, owner:, current:)

Initialize a new violation error.

Signature

parameter message String | Nil

Optional custom message.

parameter target Object

The object that was accessed.

parameter method Symbol

The method that was called.

parameter owner Fiber

The fiber that owns the object.

parameter current Fiber

The fiber that attempted to access the object.

Implementation

def initialize(message = nil, target:, method:, owner:, current:)
	@target = target
	@method = method
	@owner = owner
	@current = current
	
	super(message || build_message)
end

def as_json

Convert the violation error to a JSON-serializable hash.

Signature

returns Hash

A hash representation of the violation.

Implementation

def as_json
	{
		object_class: @object_class,
		method: @method,
		owner: {
			name: @owner.inspect,
			backtrace: @owner.backtrace,
		},
		current: {
			name: @current.inspect,
			backtrace: @current.backtrace,
		},
	}
end