Class: Event::Interrupt
- Inherits:
-
Object
- Object
- Event::Interrupt
- Defined in:
- lib/event/interrupt.rb
Overview
A thread safe synchronisation primative.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(selector, block) ⇒ Interrupt
constructor
A new instance of Interrupt.
-
#signal(event = 0) ⇒ Object
Send a sigle byte interrupt.
Constructor Details
#initialize(selector, block) ⇒ Interrupt
Returns a new instance of Interrupt.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/event/interrupt.rb', line 30 def initialize(selector, block) @selector = selector @input, @output = ::IO.pipe @fiber = Fiber.new do while true @selector.io_wait(@fiber, @input, READABLE) block.call(@input.read_nonblock(1)&.ord) end end @fiber.transfer end |
Class Method Details
.attach(selector, &block) ⇒ Object
26 27 28 |
# File 'lib/event/interrupt.rb', line 26 def self.attach(selector, &block) self.new(selector, block) end |
Instance Method Details
#close ⇒ Object
50 51 52 53 |
# File 'lib/event/interrupt.rb', line 50 def close @input.close @output.close end |
#signal(event = 0) ⇒ Object
Send a sigle byte interrupt.
45 46 47 48 |
# File 'lib/event/interrupt.rb', line 45 def signal(event = 0) @output.write(event.chr) @output.flush end |