Class: Ably::Util::SafeDeferrable
- Inherits:
-
Object
- Object
- Ably::Util::SafeDeferrable
- Includes:
- Modules::SafeDeferrable
- Defined in:
- lib/submodules/ably-ruby/lib/ably/util/safe_deferrable.rb
Overview
SafeDeferrable class provides a Deferrable that is safe to use for for public interfaces of this client library. Any exceptions raised in the success or failure callbacks are caught and logged to the provided logger.
An exception in a callback provided by a developer should not break this client library and stop further execution of code.
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
-
.new_and_fail_immediately(logger, error) ⇒ SafeDeferrable
Create a new SafeDeferrable and fail immediately with the provided error in the next eventloop cycle.
-
.new_and_succeed_immediately(logger, *args) ⇒ SafeDeferrable
Create a new SafeDeferrable and succeed immediately with the provided arguments in the next eventloop cycle.
Instance Method Summary collapse
-
#initialize(logger) ⇒ SafeDeferrable
constructor
A new instance of SafeDeferrable.
Methods included from Modules::SafeDeferrable
#callback, #errback, #fail, #succeed
Constructor Details
#initialize(logger) ⇒ SafeDeferrable
Returns a new instance of SafeDeferrable.
14 15 16 |
# File 'lib/submodules/ably-ruby/lib/ably/util/safe_deferrable.rb', line 14 def initialize(logger) @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/submodules/ably-ruby/lib/ably/util/safe_deferrable.rb', line 12 def logger @logger end |
Class Method Details
.new_and_fail_immediately(logger, error) ⇒ SafeDeferrable
Create a new Ably::Util::SafeDeferrable and fail immediately with the provided error in the next eventloop cycle
24 25 26 27 28 29 30 |
# File 'lib/submodules/ably-ruby/lib/ably/util/safe_deferrable.rb', line 24 def self.new_and_fail_immediately(logger, error) new(logger).tap do |deferrable| EventMachine.next_tick do deferrable.fail error end end end |
.new_and_succeed_immediately(logger, *args) ⇒ SafeDeferrable
Create a new Ably::Util::SafeDeferrable and succeed immediately with the provided arguments in the next eventloop cycle
36 37 38 39 40 41 42 |
# File 'lib/submodules/ably-ruby/lib/ably/util/safe_deferrable.rb', line 36 def self.new_and_succeed_immediately(logger, *args) new(logger).tap do |deferrable| EventMachine.next_tick do deferrable.succeed *args end end end |