Class: Ably::Realtime::Channels
- Inherits:
-
Object
- Object
- Ably::Realtime::Channels
- Includes:
- Modules::ChannelsCollection
- Defined in:
- lib/ably/realtime/channels.rb
Overview
Class that maintains a map of Channels ensuring Channels are reused
Instance Attribute Summary
Attributes included from Modules::ChannelsCollection
Instance Method Summary collapse
-
#fetch(name) {|options| ... } ⇒ Ably::Realtime::Channel
Return a Channel for the given name if it exists, else the block will be called.
-
#get(name, channel_options = {}) ⇒ Ably::Realtime::Channel
Return a Channel for the given name.
- #initialize(client) ⇒ Ably::Realtime::Channels constructor
-
#release(channel) ⇒ void
Detaches the Realtime Channel and releases all associated resources.
Methods included from Modules::ChannelsCollection
Constructor Details
#initialize(client) ⇒ Ably::Realtime::Channels
8 9 10 |
# File 'lib/ably/realtime/channels.rb', line 8 def initialize(client) super client, Ably::Realtime::Channel end |
Instance Method Details
#fetch(name) {|options| ... } ⇒ Ably::Realtime::Channel
Return a Ably::Realtime::Channel for the given name if it exists, else the block will be called. This method is intentionally similar to Hash#fetch providing a simple way to check if a channel exists or not without creating one
32 33 34 |
# File 'lib/ably/realtime/channels.rb', line 32 def fetch(*args) super end |
#get(name, channel_options = {}) ⇒ Ably::Realtime::Channel
Return a Ably::Realtime::Channel for the given name
19 20 21 |
# File 'lib/ably/realtime/channels.rb', line 19 def get(*args) super end |
#release(channel) ⇒ void
This method returns an undefined value.
Detaches the Realtime Channel and releases all associated resources.
Releasing a Realtime Channel is not typically necessary as a channel, once detached, consumes no resources other than the memory footprint of the Realtime Channel object. Release channels to free up resources if required
43 44 45 46 47 |
# File 'lib/ably/realtime/channels.rb', line 43 def release(channel) get(channel).detach do @channels.delete(channel) end if @channels.has_key?(channel) end |