Class: Goliath::TestHelper::StreamingHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/goliath/test_helper_streaming.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ StreamingHelper

Returns a new instance of StreamingHelper.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/goliath/test_helper_streaming.rb', line 7

def initialize(url)
  @queue = EM::Queue.new

  fiber = Fiber.current
  @connection = EventMachine::HttpRequest.new(url).get
  @connection.errback do |e|
    puts "Error encountered during connection: #{e}"
    EM::stop_event_loop
  end

  @connection.callback { EM::stop_event_loop }

  @connection.stream { |m| @queue.push(m) }

  Fiber.yield
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/goliath/test_helper_streaming.rb', line 6

def connection
  @connection
end

Instance Method Details

#receiveObject



28
29
30
31
32
# File 'lib/goliath/test_helper_streaming.rb', line 28

def receive
  fiber = Fiber.current
  @queue.pop {|m| fiber.resume(m) }
  Fiber.yield
end

#send(m) ⇒ Object



24
25
26
# File 'lib/goliath/test_helper_streaming.rb', line 24

def send(m)
  @connection.send_msg(m)
end