Async::SafeSourceAsyncSafeself

class << self

Definitions

attr_reader :monitor

Signature

attribute Monitor

The global monitoring instance.

def enable!

Enable thread safety monitoring.

This activates a TracePoint that tracks object access across fibers and threads. There is no performance overhead when monitoring is disabled.

Implementation

def enable!
	@monitor ||= Monitor.new
	@monitor.enable!
end

def disable!

Disable thread safety monitoring.

Implementation

def disable!
	@monitor&.disable!
	@monitor = nil
end

def transfer(*objects)

Explicitly transfer ownership of objects to the current fiber.

This allows an object to be safely passed between fibers.

request = Request.new(...)

Fiber.schedule do
	# Transfer ownership of the request to this fiber:
	Async::Safe.transfer(request)
	process(request)
end

Signature

parameter objects Array(Object)

The objects to transfer ownership of.

Implementation

def transfer(*objects)
	@monitor&.transfer(*objects)
end