Class: RubyEventStore::Subscriptions::ThreadLocalSubscriptions
- Inherits:
-
Object
- Object
- RubyEventStore::Subscriptions::ThreadLocalSubscriptions
- Defined in:
- lib/ruby_event_store/subscriptions.rb
Instance Method Summary collapse
- #add(subscription, event_types) ⇒ Object
- #all_for(event_type) ⇒ Object
-
#initialize ⇒ ThreadLocalSubscriptions
constructor
A new instance of ThreadLocalSubscriptions.
Constructor Details
#initialize ⇒ ThreadLocalSubscriptions
Returns a new instance of ThreadLocalSubscriptions.
80 81 82 |
# File 'lib/ruby_event_store/subscriptions.rb', line 80 def initialize @subscriptions = Concurrent::ThreadLocalVar.new { Hash.new { |hsh, key| hsh[key] = [] } } end |
Instance Method Details
#add(subscription, event_types) ⇒ Object
84 85 86 87 |
# File 'lib/ruby_event_store/subscriptions.rb', line 84 def add(subscription, event_types) event_types.each { |type| @subscriptions.value[type] << subscription } -> { event_types.each { |type| @subscriptions.value.fetch(type).delete(subscription) } } end |
#all_for(event_type) ⇒ Object
89 90 91 |
# File 'lib/ruby_event_store/subscriptions.rb', line 89 def all_for(event_type) @subscriptions.value[event_type] end |