Class: Gamelan::Task

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gamelan/task.rb

Overview

Tasks run by the Scheduler. A task is a combination of a block to be run, a delay, in beats, that specifies when to run the Task, and an optional list of args. A reference to the Scheduler is also stored, so it can be manipulatd by tasks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sched, delay, *args, &block) ⇒ Task

Construct a Task with a Scheduler reference, a delay in beats, an optional list of args, and a block.



16
17
18
# File 'lib/gamelan/task.rb', line 16

def initialize(sched, delay, *args, &block)
  @scheduler, @delay, @proc, @args = sched, delay, block, args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#delayObject (readonly)

Returns the value of attribute delay.



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

def delay
  @delay
end

#schedulerObject (readonly)

Returns the value of attribute scheduler.



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

def scheduler
  @scheduler
end

Instance Method Details

#runObject

The scheduler will invoke Task#run is called with the Task’s delay at the scheduled time. Any optional args, if given, will follow. are yielded to the block.



23
# File 'lib/gamelan/task.rb', line 23

def run; @proc[@delay, *@args] end