Sha256: a4219b145a8cc249f0e3d452439a832bc0dc0ea073eac14b4fd6c874f51132d6
Contents?: true
Size: 753 Bytes
Versions: 6
Compression:
Stored size: 753 Bytes
Contents
module Rasti module Web class Channel def initialize @mutex = Mutex.new @streams = [] end def subscribe Stream.new.tap do |stream| @mutex.synchronize do @streams << stream end end end def publish(message) @mutex.synchronize do @streams.delete_if(&:closed?) Rasti::Web.logger.debug(Channel) { "Broadcasting (#{@streams.count} connections) -> #{message}" } unless @streams.empty? @streams.each do |stream| stream.write message end end end def self.[](id) @channels ||= Hash.new { |h,k| h[k] = Channel.new } @channels[id] end end end end
Version data entries
6 entries across 6 versions & 1 rubygems