Class: Channel::Timer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delay) ⇒ Timer

Returns a new instance of Timer.



4
5
6
7
8
# File 'lib/channel/timer.rb', line 4

def initialize(delay)
  @channel = Channel.new(1)
  @prc = -> { sleep delay; channel << Time.now }
  start
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



2
3
4
# File 'lib/channel/timer.rb', line 2

def channel
  @channel
end

Class Method Details

.after(delay) ⇒ Object



14
15
16
# File 'lib/channel/timer.rb', line 14

def self.after(delay)
  new(delay).channel
end

Instance Method Details

#startObject



10
11
12
# File 'lib/channel/timer.rb', line 10

def start
  Channel::Runtime.go @prc
end