Module: Drone::Schedulers::EMScheduler

Defined in:
lib/drone/schedulers/eventmachine.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) schedule_once(delay, &block)

Schedule a block to be called after a specified delay



34
35
36
37
38
39
40
41
# File 'lib/drone/schedulers/eventmachine.rb', line 34

def self.schedule_once(delay, &block)
  raise "Block required" unless block
  if @started
    EM::add_timer(delay, &block)
  else
    @timers_once << [delay, block]
  end
end

+ (Object) schedule_periodic(delay, &block)

Schedule a block to be called immediatly and after that at a specified interval



17
18
19
20
21
22
23
24
25
# File 'lib/drone/schedulers/eventmachine.rb', line 17

def self.schedule_periodic(delay, &block)
  raise "Block required" unless block
  if @started
    block.call()
    EM::add_periodic_timer(delay, &block)
  else
    @timers_periodic << [delay, block]
  end
end

+ (Object) start

Start the timers.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/drone/schedulers/eventmachine.rb', line 47

def self.start
  @started = true
  @timers_once.each do |(delay, block)|
    schedule_once(delay, &block)
  end
  
  @timers_periodic.each do |(delay, block)|
    schedule_periodic(delay, &block)
  end
  
end