Class: DiscordRDA::EventBus::Subscription
- Inherits:
-
Object
- Object
- DiscordRDA::EventBus::Subscription
- Defined in:
- lib/discord_rda/event/bus.rb
Overview
Subscription object for managing handler lifecycle
Instance Attribute Summary collapse
-
#active ⇒ Boolean
readonly
Whether active.
-
#bus ⇒ EventBus
readonly
Event bus.
-
#event_type ⇒ String
readonly
Event type.
-
#handler ⇒ EventHandler
readonly
Handler.
Instance Method Summary collapse
-
#initialize(bus, event_type, handler) ⇒ Subscription
constructor
A new instance of Subscription.
-
#subscribed? ⇒ Boolean
Check if still subscribed.
-
#unsubscribe ⇒ void
Unsubscribe this handler.
Constructor Details
#initialize(bus, event_type, handler) ⇒ Subscription
Returns a new instance of Subscription.
202 203 204 205 206 207 |
# File 'lib/discord_rda/event/bus.rb', line 202 def initialize(bus, event_type, handler) @bus = bus @event_type = event_type @handler = handler @active = true end |
Instance Attribute Details
#active ⇒ Boolean (readonly)
Returns Whether active.
200 201 202 |
# File 'lib/discord_rda/event/bus.rb', line 200 def active @active end |
#bus ⇒ EventBus (readonly)
Returns Event bus.
191 192 193 |
# File 'lib/discord_rda/event/bus.rb', line 191 def bus @bus end |
#event_type ⇒ String (readonly)
Returns Event type.
194 195 196 |
# File 'lib/discord_rda/event/bus.rb', line 194 def event_type @event_type end |
#handler ⇒ EventHandler (readonly)
Returns Handler.
197 198 199 |
# File 'lib/discord_rda/event/bus.rb', line 197 def handler @handler end |
Instance Method Details
#subscribed? ⇒ Boolean
Check if still subscribed
220 221 222 |
# File 'lib/discord_rda/event/bus.rb', line 220 def subscribed? @active end |
#unsubscribe ⇒ void
This method returns an undefined value.
Unsubscribe this handler
211 212 213 214 215 216 |
# File 'lib/discord_rda/event/bus.rb', line 211 def unsubscribe return unless @active @bus.off(@event_type, @handler) @active = false end |