Class: RubyEventStore::PubSub::Subscriptions::ThreadLocalSubscriptions
- Inherits:
-
Object
- Object
- RubyEventStore::PubSub::Subscriptions::ThreadLocalSubscriptions
- Defined in:
- lib/ruby_event_store/pub_sub/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.
78 79 80 81 82 |
# File 'lib/ruby_event_store/pub_sub/subscriptions.rb', line 78 def initialize @subscriptions = Concurrent::ThreadLocalVar.new do Hash.new {|hsh, key| hsh[key] = [] } end end |
Instance Method Details
#add(subscription, event_types) ⇒ Object
84 85 86 87 |
# File 'lib/ruby_event_store/pub_sub/subscriptions.rb', line 84 def add(subscription, event_types) event_types.each{ |type| @subscriptions.value[type.to_s] << subscription } ->() {event_types.each{ |type| @subscriptions.value.fetch(type.to_s).delete(subscription) } } end |
#all_for(event_type) ⇒ Object
89 90 91 |
# File 'lib/ruby_event_store/pub_sub/subscriptions.rb', line 89 def all_for(event_type) @subscriptions.value[event_type] end |