Class: Smith::Events::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/events/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_classObject (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

#handlerObject (readonly)

Returns the value of attribute handler.



6
7
8
# File 'lib/smith/events/subscription.rb', line 6

def handler
  @handler
end

#predicateObject (readonly)

Returns the value of attribute predicate.



6
7
8
# File 'lib/smith/events/subscription.rb', line 6

def predicate
  @predicate
end

#sequence_numberObject

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

#cancelObject

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

Returns:

  • (Boolean)


27
28
29
# File 'lib/smith/events/subscription.rb', line 27

def cancelled?
  @cancelled
end