lib/submodules/ably-ruby/lib/ably/modules/async_wrapper.rb in ably-rest-0.9.3 vs lib/submodules/ably-ruby/lib/ably/modules/async_wrapper.rb in ably-rest-1.0.0

- old
+ new

@@ -36,21 +36,25 @@ # Will yield the provided block in a new thread and return an {Ably::Util::SafeDeferrable} # # @yield [Object] operation block that is run in a thread # @return [Ably::Util::SafeDeferrable] # - def async_wrap(success_callback = nil) + def async_wrap(success_callback = nil, custom_error_handling = nil) raise ArgumentError, 'Block required' unless block_given? Ably::Util::SafeDeferrable.new(logger).tap do |deferrable| deferrable.callback(&success_callback) if success_callback operation_with_exception_handling = proc do begin yield rescue StandardError => err - logger.error "An exception in an AsyncWrapper block was caught. #{err.class}: #{err.message}\n#{err.backtrace.join("\n")}" - deferrable.fail err + if custom_error_handling + custom_error_handling.call err, deferrable + else + logger.error { "An exception in an AsyncWrapper block was caught. #{err.class}: #{err.message}\n#{err.backtrace.join("\n")}" } + deferrable.fail err + end end end complete_callback = proc do |result| deferrable.succeed result