Class: ShopifyCLI::Theme::DevServer::SSE::Streams

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

Instance Method Summary collapse

Constructor Details

#initializeStreams

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

Raises:

  • (TypeError)


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

#closeObject



67
68
69
70
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 67

def close
  @list.each(&:close)
  @list.clear
end

#newObject



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

Raises:

  • (TypeError)


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

#sizeObject



45
46
47
# File 'lib/shopify_cli/theme/dev_server/sse.rb', line 45

def size
  @list.size
end