Class: ActiveUsage::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/active_usage/worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(interval, &block) ⇒ Worker

Returns a new instance of Worker.



5
6
7
8
9
10
11
# File 'lib/active_usage/worker.rb', line 5

def initialize(interval, &block)
  @interval = interval
  @block = block
  @mutex = Mutex.new
  @running = true
  start!
end

Instance Method Details

#join(timeout) ⇒ Object



17
18
19
# File 'lib/active_usage/worker.rb', line 17

def join(timeout)
  @thread&.join(timeout)
end

#stop!Object



13
14
15
# File 'lib/active_usage/worker.rb', line 13

def stop!
  @mutex.synchronize { @running = false }
end