Class: Eventbox::CompletionProc

Inherits:
AsyncProc show all
Includes:
CallContext
Defined in:
lib/eventbox/sanitizer.rb

Overview

Proc object provided as the last argument of yield_call and #yield_proc.

Used to let the corresponding yield call return a value:

class MyBox < Eventbox
  yield_call def number(result)
    result.yield 42
  end
end
MyBox.new.number   # => 42

Alternatively the yield call can respond with an exception by #raise.

Instance Method Summary collapse

Instance Method Details

#raise(*args) ⇒ Object

Raise an exception in the context of the waiting yield_call or Eventbox#yield_proc method.

This allows to raise an exception to the calling scope from external or action scope:

class MyBox < Eventbox
  yield_call def init(result)
    process(result)
  end

  action def process(result)
    result.raise RuntimeError, "raise from action MyBox#process"
  end
end
MyBox.new   # => raises RuntimeError (raise from action MyBox#process)

In contrast to a direct call of Kernel.raise, calling this method doesn’t abort the current context. Instead when in the event scope, raising the exception is deferred until returning to the calling external or action scope.



410
411
412
# File 'lib/eventbox/sanitizer.rb', line 410

def raise(*args)
  self.call(WrappedException.new(args))
end