Class: Async::Signals::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/async/signals/context.rb

Overview

Represents the execution context that installed a signal handler set.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread, fiber, scheduler = nil) ⇒ Context

Initialize the context.



32
33
34
35
36
# File 'lib/async/signals/context.rb', line 32

def initialize(thread, fiber, scheduler = nil)
	@thread = thread
	@fiber = fiber
	@scheduler = scheduler
end

Class Method Details

.currentObject

Capture the current execution context.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/async/signals/context.rb', line 12

def self.current
	thread = ::Thread.current
	fiber = ::Fiber.current
	scheduler = nil
	
	if ::Fiber.respond_to?(:current_scheduler)
		if current_scheduler = ::Fiber.current_scheduler
			if current_scheduler.respond_to?(:fiber_interrupt)
				scheduler = current_scheduler
			end
		end
	end
	
	self.new(thread, fiber, scheduler)
end

Instance Method Details

#raise(*arguments) ⇒ Object

Raise an exception in the execution context that installed the handler set.



40
41
42
43
44
45
46
# File 'lib/async/signals/context.rb', line 40

def raise(*arguments)
	if @scheduler
		return @scheduler.fiber_interrupt(@fiber, exception_for(arguments))
	end
	
	@thread.raise(*arguments)
end