Class: Protocol::HTTP::Executor::Ractored

Inherits:
Generic
  • Object
show all
Defined in:
lib/protocol/http/executor/ractored.rb

Overview

Executes each request in a dedicated Ruby 4.1 Ractor.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#call

Constructor Details

#initialize(delegate) ⇒ Ractored

Initialize a Ractored executor.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/protocol/http/executor/ractored.rb', line 14

def initialize(delegate)
	unless self.class.supported?
		raise NotImplementedError, "Ractor execution requires the Ruby head/4.1 Ractor API."
	end
	
	unless ::Ractor.shareable?(delegate)
		raise ArgumentError, "The Ractor application must be shareable."
	end
	
	# Protocol::HTTP applications construct headers inside the worker, so the
	# default policy must be visible from non-main Ractors:
	::Ractor.make_shareable(::Protocol::HTTP::Headers::POLICY)
	
	super
end

Class Method Details

.supported?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/protocol/http/executor/ractored.rb', line 31

def self.supported?
	defined?(::Ractor) && ::Ractor.method_defined?(:join) && ::Ractor.method_defined?(:value)
end