Class: EventStoreSubscriptions::Subscriptions

Inherits:
Object
  • Object
show all
Extended by:
MakeAtomic
Defined in:
lib/event_store_subscriptions/subscriptions.rb

Overview

Implements Subscription-s collection

Constant Summary collapse

ALL_STREAM =
'$all'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MakeAtomic

make_atomic

Constructor Details

#initialize(client) ⇒ Subscriptions

Returns a new instance of Subscriptions.

Parameters:

  • client (EventStoreClient::GRPC::Client)


14
15
16
17
18
# File 'lib/event_store_subscriptions/subscriptions.rb', line 14

def initialize(client)
  @client = client
  @subscriptions = []
  @semaphore = Mutex.new
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/event_store_subscriptions/subscriptions.rb', line 9

def client
  @client
end

Instance Method Details

#addArray<EventStoreSubscriptions::Subscription>

Adds Subscription to the collection

Parameters:

Returns:



41
42
43
# File 'lib/event_store_subscriptions/subscriptions.rb', line 41

make_atomic def add(subscription)
  @subscriptions << subscription
end

#create(*args, **kwargs, &blk) ⇒ EventStoreSubscriptions::Subscription

Returns:

See Also:

  • documentation for available params


22
23
24
25
26
27
28
29
# File 'lib/event_store_subscriptions/subscriptions.rb', line 22

def create(*args, **kwargs, &blk)
  setup = SubscriptionSetup.new(args, kwargs, blk)
  subscription = Subscription.new(
    position: position_class(args[0]).new, client: client, setup: setup
  )
  add(subscription)
  subscription
end

#create_for_all(**kwargs, &blk) ⇒ EventStoreSubscriptions::Subscription

Shortcut to create a Subscription to subscribe to the ‘$all’ stream

Returns:

See Also:

  • documentation for available params


34
35
36
# File 'lib/event_store_subscriptions/subscriptions.rb', line 34

def create_for_all(**kwargs, &blk)
  create(ALL_STREAM, **kwargs, &blk)
end

#listen_allArray<EventStoreSubscriptions::Subscription>

Starts listening to all subscriptions in the collection



55
56
57
# File 'lib/event_store_subscriptions/subscriptions.rb', line 55

make_atomic def listen_all
  @subscriptions.each(&:listen)
end

#removeEventStoreSubscriptions::Subscription?

Removes subscription from the collection

Parameters:

Returns:



49
50
51
# File 'lib/event_store_subscriptions/subscriptions.rb', line 49

make_atomic def remove(subscription)
  @subscriptions.delete(subscription)
end

#stop_allArray<EventStoreSubscriptions::Subscription>

Stops listening to all subscriptions in the collection



61
62
63
# File 'lib/event_store_subscriptions/subscriptions.rb', line 61

make_atomic def stop_all
  @subscriptions.each(&:stop_listening)
end

#subscriptionsArray<EventStoreSubscriptions::Subscription>



66
67
68
69
# File 'lib/event_store_subscriptions/subscriptions.rb', line 66

make_atomic def subscriptions
  # Duping original collection to prevent potential mutable operations over it from user's side
  @subscriptions.dup
end