Class: Heathrow::Poller

Inherits:
Object
  • Object
show all
Defined in:
lib/heathrow/poller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, plugin_manager) ⇒ Poller

Returns a new instance of Poller.



8
9
10
11
12
13
14
# File 'lib/heathrow/poller.rb', line 8

def initialize(db, plugin_manager)
  @db = db
  @plugin_manager = plugin_manager
  @running = false
  @thread = nil
  @mutex = Mutex.new
end

Instance Attribute Details

#runningObject (readonly)

Returns the value of attribute running.



6
7
8
# File 'lib/heathrow/poller.rb', line 6

def running
  @running
end

Instance Method Details

#startObject



16
17
18
19
20
21
22
23
# File 'lib/heathrow/poller.rb', line 16

def start
  return if @running
  
  @running = true
  @thread = Thread.new do
    run_polling_loop
  end
end

#stopObject



25
26
27
28
# File 'lib/heathrow/poller.rb', line 25

def stop
  @running = false
  @thread&.join(5) # Wait up to 5 seconds for thread to finish
end