lib/ably/util/safe_deferrable.rb in ably-0.8.15 vs lib/ably/util/safe_deferrable.rb in ably-1.0.0
- old
+ new
@@ -12,7 +12,33 @@
attr_reader :logger
def initialize(logger)
@logger = logger
end
+
+ # Create a new {SafeDeferrable} and fail immediately with the provided error in the next eventloop cycle
+ #
+ # @param error [Ably::Exceptions::BaseAblyException, Ably::Models::ErrorInfo] The error used to fail the newly created {SafeDeferrable}
+ #
+ # @return [SafeDeferrable]
+ #
+ def self.new_and_fail_immediately(logger, error)
+ new(logger).tap do |deferrable|
+ EventMachine.next_tick do
+ deferrable.fail error
+ end
+ end
+ end
+
+ # Create a new {SafeDeferrable} and succeed immediately with the provided arguments in the next eventloop cycle
+ #
+ # @return [SafeDeferrable]
+ #
+ def self.new_and_succeed_immediately(logger, *args)
+ new(logger).tap do |deferrable|
+ EventMachine.next_tick do
+ deferrable.succeed *args
+ end
+ end
+ end
end
end