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

Instance Method Details

#joinObject

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

#killObject

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

#startObject

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.

Returns:

  • (Boolean)


9
# File 'lib/catfriend/thread.rb', line 9

def stopped? ; @thread.nil? ; end