-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bind a publication context to subscriptions
That improves debugging by yielding a second optional argument to subscription blocks. That argument is an instance of `Omnes::PublicationContext`, referencing the publisher's location and the publication time. ```ruby bus.subscribe(:foo) do |event, publication_context| # debugging abort publication_context.inspect end ``` If they want to support it, adapters need to be aware to dispatch the second argument if present. As such, current adapters have been adapted. `Omnes::PublicationContext` contains a `#serialized` method that can be called before dispatching async adapters.
- Loading branch information
1 parent
1ec5225
commit 12f6caa
Showing
14 changed files
with
366 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
module Omnes | ||
# Context for an event publication | ||
# | ||
# An instance of this class is shared between all the executions that are | ||
# triggered by the publication of a given event. It's provided to the | ||
# subscriptions as their second argument when they take it. | ||
# | ||
# This class is useful mainly for debugging and logging purposes. | ||
class PublicationContext | ||
# Location for the event publisher | ||
# | ||
# It's set by {Omnes::Bus#publish}, and it points to the caller of that | ||
# method. | ||
# | ||
# @return [Thread::Backtrace::Location] | ||
attr_reader :caller_location | ||
|
||
# Time of the event publication | ||
# | ||
# @return [Time] | ||
attr_reader :time | ||
|
||
# @api private | ||
def initialize(caller_location:, time:) | ||
@caller_location = caller_location | ||
@time = time | ||
end | ||
|
||
# Serialized version of a publication context | ||
# | ||
# @return Hash<String, String> | ||
def serialized | ||
{ | ||
"caller_location" => caller_location.to_s, | ||
"time" => time.to_s | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.