Class: EmmyHttp::Timer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval) ⇒ Timer

Returns a new instance of Timer.



8
9
10
# File 'lib/emmy_http/timer.rb', line 8

def initialize(interval)
  @interval = interval
end

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



4
5
6
# File 'lib/emmy_http/timer.rb', line 4

def interval
  @interval
end

Instance Method Details

#awaitObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/emmy_http/timer.rb', line 18

def await
  Fiber.await do |fiber|
    # create connection
    start

    on :timeout do
      fiber.resume true
    end
  end
end

#startObject



12
13
14
15
16
# File 'lib/emmy_http/timer.rb', line 12

def start
  EmmyMachine.timeout(interval) do
    timeout!
  end
end