Class: RubyEventStore::Subscriptions::ThreadLocalSubscriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/subscriptions.rb

Instance Method Summary collapse

Constructor Details

#initializeThreadLocalSubscriptions

Returns a new instance of ThreadLocalSubscriptions.


94
95
96
97
98
# File 'lib/ruby_event_store/subscriptions.rb', line 94

def initialize
  @subscriptions = Concurrent::ThreadLocalVar.new do
    Hash.new {|hsh, key| hsh[key] = [] }
  end
end

Instance Method Details

#add(subscription, event_types) ⇒ Object


100
101
102
103
# File 'lib/ruby_event_store/subscriptions.rb', line 100

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


105
106
107
# File 'lib/ruby_event_store/subscriptions.rb', line 105

def all_for(event_type)
  @subscriptions.value[event_type]
end