Class: RailsEventStore::AfterCommitAsyncDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_event_store/after_commit_async_dispatcher.rb

Defined Under Namespace

Classes: AsyncRecord

Instance Method Summary collapse

Constructor Details

#initialize(scheduler:) ⇒ AfterCommitAsyncDispatcher

Returns a new instance of AfterCommitAsyncDispatcher.



5
6
7
# File 'lib/rails_event_store/after_commit_async_dispatcher.rb', line 5

def initialize(scheduler:)
  @scheduler = scheduler
end

Instance Method Details

#async_record(schedule_proc) ⇒ Object



23
24
25
# File 'lib/rails_event_store/after_commit_async_dispatcher.rb', line 23

def async_record(schedule_proc)
  AsyncRecord.new(schedule_proc)
end

#call(subscriber, _, record) ⇒ Object



9
10
11
# File 'lib/rails_event_store/after_commit_async_dispatcher.rb', line 9

def call(subscriber, _, record)
  run { @scheduler.call(subscriber, record) }
end

#run(&schedule_proc) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/rails_event_store/after_commit_async_dispatcher.rb', line 13

def run(&schedule_proc)
  transaction = ActiveRecord::Base.connection.current_transaction

  if transaction.joinable?
    transaction.add_record(async_record(schedule_proc))
  else
    yield
  end
end

#verify(subscriber) ⇒ Object



27
28
29
# File 'lib/rails_event_store/after_commit_async_dispatcher.rb', line 27

def verify(subscriber)
  @scheduler.verify(subscriber)
end