Class: Smith::Events::Subscription
- Inherits:
-
Object
- Object
- Smith::Events::Subscription
- Defined in:
- lib/smith/events/subscription.rb
Instance Attribute Summary collapse
-
#event_class ⇒ Object
readonly
Returns the value of attribute event_class.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#predicate ⇒ Object
readonly
Returns the value of attribute predicate.
-
#sequence_number ⇒ Object
Internal registration order, assigned by Events.on; dispatch and the subscriptions snapshot sort by it.
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancelling flags the subscription and detaches it from the registry (so it cannot leak).
- #cancelled? ⇒ Boolean
-
#initialize(event_class, handler:, predicate: nil) ⇒ Subscription
constructor
A new instance of Subscription.
Constructor Details
#initialize(event_class, handler:, predicate: nil) ⇒ Subscription
Returns a new instance of Subscription.
11 12 13 14 15 16 |
# File 'lib/smith/events/subscription.rb', line 11 def initialize(event_class, handler:, predicate: nil) @event_class = event_class @handler = handler @predicate = predicate @cancelled = false end |
Instance Attribute Details
#event_class ⇒ Object (readonly)
Returns the value of attribute event_class.
6 7 8 |
# File 'lib/smith/events/subscription.rb', line 6 def event_class @event_class end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
6 7 8 |
# File 'lib/smith/events/subscription.rb', line 6 def handler @handler end |
#predicate ⇒ Object (readonly)
Returns the value of attribute predicate.
6 7 8 |
# File 'lib/smith/events/subscription.rb', line 6 def predicate @predicate end |
#sequence_number ⇒ Object
Internal registration order, assigned by Events.on; dispatch and the subscriptions snapshot sort by it.
9 10 11 |
# File 'lib/smith/events/subscription.rb', line 9 def sequence_number @sequence_number end |
Instance Method Details
#cancel ⇒ Object
Cancelling flags the subscription and detaches it from the registry (so it cannot leak). The flag check against an in-flight emit snapshot is best-effort: a dispatch already past the check may still deliver once after cancel returns.
22 23 24 25 |
# File 'lib/smith/events/subscription.rb', line 22 def cancel @cancelled = true Events.detach(self) end |
#cancelled? ⇒ Boolean
27 28 29 |
# File 'lib/smith/events/subscription.rb', line 27 def cancelled? @cancelled end |