Class: Gamelan::Scheduler

Inherits:
Timer
  • Object
show all
Defined in:
lib/gamelan/scheduler.rb

Overview

The scheduler allows the user to schedule tasks, represented by Gamelan::Task.

Instance Attribute Summary

Attributes inherited from Timer

#phase, #rate, #time

Instance Method Summary collapse

Methods inherited from Timer

#join, #run, #stop, #tempo, #tempo=

Constructor Details

#initialize(options = {}) ⇒ Scheduler

Construct a new scheduler. Scheduler#run must be called explicitly once a Scheduler is created. Accepts two options, :tempo and :rate.

:tempo

The tempo’s scheduler, in bpm. For example, at :tempo => 120, the scheduler’s logical phase will advance by 2.0 every 60 seconds.

:rate

Frequency in Hz at which the scheduler will attempt to run ready tasks. For example, The scheduler will poll for tasks 100 times in one second when :rate is 100.



12
13
14
15
# File 'lib/gamelan/scheduler.rb', line 12

def initialize(options = {})
  super
  @queue     = Gamelan::Queue.new(self)
end

Instance Method Details

#at(delay, *params, &task) ⇒ Object

Schedule a task to be performed at delay beats.



18
19
20
# File 'lib/gamelan/scheduler.rb', line 18

def at(delay, *params, &task)
  @queue << Task.new(self, delay.to_f, *params, &task)
end