Class: RevealCK::Commands::ThreadWaker

Inherits:
Object
  • Object
show all
Defined in:
lib/reveal-ck/commands/thread_waker.rb

Overview

Utility that wakes up a thread periodically

Instance Method Summary collapse

Constructor Details

#initialize(thread_to_wake, wait_period = 1) ⇒ ThreadWaker

Returns a new instance of ThreadWaker.



5
6
7
8
# File 'lib/reveal-ck/commands/thread_waker.rb', line 5

def initialize(thread_to_wake, wait_period = 1)
  @thread_to_wake = thread_to_wake
  @wait_period = wait_period
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
# File 'lib/reveal-ck/commands/thread_waker.rb', line 10

def run
  Thread.new do
    loop do
      sleep @wait_period
      @thread_to_wake.wakeup if @thread_to_wake.alive?
    end
  end
end