Class: Asynchronous::Thread
- Inherits:
-
Object
- Object
- Asynchronous::Thread
- Defined in:
- lib/asynchronous/thread.rb
Instance Method Summary collapse
-
#initialize(&callable) ⇒ Thread
constructor
A new instance of Thread.
- #join ⇒ Object
- #kill ⇒ Object
- #status ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(&callable) ⇒ Thread
Returns a new instance of Thread.
2 3 4 5 6 7 8 9 |
# File 'lib/asynchronous/thread.rb', line 2 def initialize(&callable) @value = nil @value_received = false @read, @write = ::IO.pipe read_buffer @pid = fork(&callable) end |
Instance Method Details
#join ⇒ Object
11 12 13 14 15 16 |
# File 'lib/asynchronous/thread.rb', line 11 def join wait receive_value! unless @value_received raise(@value.wrapped_error) if @value.is_a?(::Asynchronous::Error) self end |
#kill ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/asynchronous/thread.rb', line 18 def kill ::Process.kill('KILL', @pid) wait rescue Errno::ESRCH nil end |
#status ⇒ Object
26 27 28 |
# File 'lib/asynchronous/thread.rb', line 26 def status alive? ? 'run' : false end |
#value ⇒ Object
30 31 32 |
# File 'lib/asynchronous/thread.rb', line 30 def value join; @value end |