Class: ShopifyCLI::Theme::DevServer::SSE::Streams
- Inherits:
-
Object
- Object
- ShopifyCLI::Theme::DevServer::SSE::Streams
- Defined in:
- lib/shopify_cli/theme/dev_server/sse.rb
Instance Method Summary collapse
- #broadcast(data) ⇒ Object
- #close ⇒ Object
-
#initialize ⇒ Streams
constructor
A new instance of Streams.
- #new ⇒ Object
- #remove(stream) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Streams
Returns a new instance of Streams.
41 42 43 |
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 41 def initialize @list = [] end |
Instance Method Details
#broadcast(data) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 60 def broadcast(data) raise TypeError, "expected String" unless data.is_a?(String) @list.each do |stream| stream << Event.new(data) end end |
#close ⇒ Object
67 68 69 70 |
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 67 def close @list.each(&:close) @list.clear end |
#new ⇒ Object
49 50 51 52 53 |
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 49 def new stream = Stream.new(self) @list << stream stream end |
#remove(stream) ⇒ Object
55 56 57 58 |
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 55 def remove(stream) raise TypeError, "expected SSE::Stream" unless stream.is_a?(Stream) @list.delete(stream) end |
#size ⇒ Object
45 46 47 |
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 45 def size @list.size end |