Method: MessageBus::HTTPClient#subscribe
- Defined in:
- lib/message_bus/http_client.rb
#subscribe(channel, last_message_id: nil) {|data, message_id, global_id| ... } ⇒ Integer
Subscribes to a channel which executes the given callback when a message is published to the channel
A last_message_id may be provided.
* -1 will subscribe to all new messages
* -2 will receive last message + all new messages
* -3 will receive last 2 message + all new messages
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/message_bus/http_client.rb', line 169 def subscribe(channel, last_message_id: nil, &callback) raise InvalidChannel unless channel.to_s.start_with?("/") raise MissingBlock unless block_given? = -1 if && !.is_a?(Integer) @channels[channel] ||= Channel.new channel = @channels[channel] channel. = if channel.callbacks.push(callback) start if stopped? end |