Class: Backport::Server::Interval

Inherits:
Base
  • Object
show all
Defined in:
lib/backport/server/interval.rb

Overview

A Backport periodical interval server.

Instance Method Summary collapse

Methods inherited from Base

#start, #started?, #stop, #stopped?, #stopping

Constructor Details

#initialize(period, &block) {|| ... } ⇒ Interval

Returns a new instance of Interval.

Parameters:

  • period (Float)

    The interval time in seconds.

  • block (Proc)

    The proc to run on each interval.

Yield Parameters:



9
10
11
12
13
14
# File 'lib/backport/server/interval.rb', line 9

def initialize period, &block
  @period = period
  @block = block
  @ready = false
  @mutex = Mutex.new
end

Instance Method Details

#startingObject



16
17
18
19
# File 'lib/backport/server/interval.rb', line 16

def starting
  @ready = false
  run_ready_thread
end

#tickObject



21
22
23
24
25
26
27
# File 'lib/backport/server/interval.rb', line 21

def tick
  return unless @ready
  @mutex.synchronize do
    @block.call self
    @ready = false
  end
end