Last active
March 5, 2025 16:55
Revisions
-
bradgessler revised this gist
Sep 12, 2024 . No changes.There are no files selected for viewing
-
bradgessler revised this gist
Sep 11, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,6 +26,6 @@ def read end def self.server ActionCable.server.pubsub end end -
bradgessler created this gist
Sep 4, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ module ActiveExchange class Channel def initialize(name:, server: ActiveExchange.server) @server = server @channel = name @queue = Queue.new @subscribe = false end def broadcast(message) Rails.logger.info "ActiveExchange: Publishing #{message.inspect} to #{@channel.inspect}" @server.broadcast(@channel, message) end def subscribe return if @subscribed @subscribed = true Rails.logger.info "ActiveExchange: Subscribed to #{@channel.inspect}" @server.subscribe(@channel, -> (message) { @queue << message }) end def read subscribe @queue.pop end end def self.server ActiveCable.server.pubsub end end