Class: ShopifyCLI::Theme::DevServer::SSE::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/theme/dev_server/sse.rb

Instance Method Summary collapse

Constructor Details

#initialize(streams) ⇒ Stream

Returns a new instance of Stream.



18
19
20
21
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 18

def initialize(streams)
  @streams = streams
  @queue = Queue.new
end

Instance Method Details

#<<(event) ⇒ Object

Raises:

  • (TypeError)


23
24
25
26
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 23

def <<(event)
  raise TypeError, "expected SSE::Event" unless event.is_a?(Event)
  @queue << event
end

#closeObject



34
35
36
37
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 34

def close
  @streams.remove(self)
  @queue << nil
end

#eachObject



28
29
30
31
32
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 28

def each
  while (event = @queue.pop)
    yield event.to_s
  end
end