Class: ShopifyCLI::Theme::DevServer::SSE::Stream
- Inherits:
-
Object
- Object
- ShopifyCLI::Theme::DevServer::SSE::Stream
- Defined in:
- lib/shopify_cli/theme/dev_server/sse.rb
Instance Method Summary collapse
- #<<(event) ⇒ Object
- #close ⇒ Object
- #each ⇒ Object
-
#initialize(streams) ⇒ Stream
constructor
A new instance of Stream.
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
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 |
#close ⇒ Object
34 35 36 37 |
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 34 def close @streams.remove(self) @queue << nil end |
#each ⇒ Object
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 |