Class: Lita::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/timer.rb

Overview

A timer that executes a block after a certain number of seconds, either once or repeatedly.

Since:

  • 3.0.0

Instance Method Summary collapse

Constructor Details

#initialize(interval: 0, recurring: false) {|timer| ... } ⇒ Timer

Returns a new instance of Timer

Parameters:

  • interval (Integer)

    The number of seconds to wait before calling the block.

  • recurring (Boolean)

    If true, the timer will fire repeatedly until stopped.

Yield Parameters:

Since:

  • 3.0.0



8
9
10
11
12
13
# File 'lib/lita/timer.rb', line 8

def initialize(interval: 0, recurring: false, &block)
  @interval = interval
  @recurring = recurring
  @running = false
  @block = block
end

Instance Method Details

#startObject

Starts running the timer.

Since:

  • 3.0.0



16
17
18
19
# File 'lib/lita/timer.rb', line 16

def start
  @running = true
  run
end

#stopObject

Stops the timer, preventing any further invocations of the block until started again.

Since:

  • 3.0.0



22
23
24
# File 'lib/lita/timer.rb', line 22

def stop
  @running = false
end