Module: ExceptionalSynchrony::CallbackExceptions
- Defined in:
- lib/exceptional_synchrony/callback_exceptions.rb
Defined Under Namespace
Classes: Failure
Class Method Summary collapse
- .ensure_callback(deferrable, &block) ⇒ Object
- .map_deferred_result(deferrable) ⇒ Object
- .return_exception(*args) ⇒ Object
Class Method Details
.ensure_callback(deferrable, &block) ⇒ Object
6 7 8 9 |
# File 'lib/exceptional_synchrony/callback_exceptions.rb', line 6 def ensure_callback(deferrable, &block) result = return_exception(&block) deferrable.succeed(*Array(result)) end |
.map_deferred_result(deferrable) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/exceptional_synchrony/callback_exceptions.rb', line 11 def map_deferred_result(deferrable) deferred_status = deferrable.instance_variable_get(:@deferred_status) deferred_args = deferrable.instance_variable_get(:@deferred_args) result = (deferred_args && deferred_args.size == 1) ? deferred_args.first : deferred_args case deferred_status when :succeeded if result.is_a?(Exception) raise result else result end when :failed if result.respond_to?(:error) handle_result_error(result) else raise_failure_for_result(result) end else raise ArgumentError, "No deferred status set yet: #{deferred_status.inspect} #{truncated_inspect(result)}" end end |
.return_exception(*args) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/exceptional_synchrony/callback_exceptions.rb', line 34 def return_exception(*args) begin yield *args rescue Exception => ex ex end end |