Class: Tamarillo::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/tamarillo/monitor.rb

Constant Summary collapse

SLEEP_TIME =

The time between checks.

0.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tomato, notifier) ⇒ Monitor

Public: Initializes a new monitor.



8
9
10
11
# File 'lib/tamarillo/monitor.rb', line 8

def initialize(tomato, notifier)
  @tomato = tomato
  @notifier = notifier
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



5
6
7
# File 'lib/tamarillo/monitor.rb', line 5

def pid
  @pid
end

Instance Method Details

#startObject

Public: Starts watching a tomato for completion.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tamarillo/monitor.rb', line 14

def start
  @pid = fork do
    until @tomato.completed?
      sleep SLEEP_TIME
    end

    @notifier.call
  end

  Process.detach(@pid)
end