Module: Catfriend::Thread
- Included in:
- DBus, ImapServer
- Defined in:
- lib/catfriend/thread.rb
Overview
Mixin this module and define “run” for a simple runnable/joinable thread
Instance Method Summary collapse
-
#join ⇒ Object
Join thread if it has started.
-
#kill ⇒ Object
Kill thread if it has started.
-
#start ⇒ Object
Call to start a thread running via the start method.
-
#stopped? ⇒ Boolean
Test whether thread is currently stopped or closing down.
Instance Method Details
#join ⇒ Object
Join thread if it has started.
12 13 14 15 16 17 |
# File 'lib/catfriend/thread.rb', line 12 def join unless stopped? @thread.join @thread = nil end end |
#kill ⇒ Object
Kill thread if it has started.
20 21 22 23 24 25 |
# File 'lib/catfriend/thread.rb', line 20 def kill unless stopped? @thread.kill @thread = nil end end |
#start ⇒ Object
Call to start a thread running via the start method.
6 |
# File 'lib/catfriend/thread.rb', line 6 def start ; @thread = ::Thread.new { run } ; end |
#stopped? ⇒ Boolean
Test whether thread is currently stopped or closing down.
9 |
# File 'lib/catfriend/thread.rb', line 9 def stopped? ; @thread.nil? ; end |