Class: RailsEventStore::AfterCommitAsyncDispatcher
- Inherits:
-
Object
- Object
- RailsEventStore::AfterCommitAsyncDispatcher
- Defined in:
- lib/rails_event_store/after_commit_async_dispatcher.rb
Defined Under Namespace
Classes: AsyncRecord
Instance Method Summary collapse
- #call(subscriber, _, serialized_event) ⇒ Object
-
#initialize(scheduler:) ⇒ AfterCommitAsyncDispatcher
constructor
A new instance of AfterCommitAsyncDispatcher.
- #run(&schedule_proc) ⇒ Object
- #verify(subscriber) ⇒ Object
Constructor Details
#initialize(scheduler:) ⇒ AfterCommitAsyncDispatcher
Returns a new instance of AfterCommitAsyncDispatcher.
3 4 5 |
# File 'lib/rails_event_store/after_commit_async_dispatcher.rb', line 3 def initialize(scheduler:) @scheduler = scheduler end |
Instance Method Details
#call(subscriber, _, serialized_event) ⇒ Object
7 8 9 10 11 |
# File 'lib/rails_event_store/after_commit_async_dispatcher.rb', line 7 def call(subscriber, _, serialized_event) run do @scheduler.call(subscriber, serialized_event) end end |
#run(&schedule_proc) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rails_event_store/after_commit_async_dispatcher.rb', line 13 def run(&schedule_proc) if ActiveRecord::Base.connection.transaction_open? ActiveRecord::Base. connection. current_transaction. add_record(AsyncRecord.new(self, schedule_proc)) else yield end end |
#verify(subscriber) ⇒ Object
24 25 26 |
# File 'lib/rails_event_store/after_commit_async_dispatcher.rb', line 24 def verify(subscriber) @scheduler.verify(subscriber) end |