class Eventbox::CompletionProc

Proc object provided as the last argument of {Eventbox::Boxable#yield_call yield_call} and {Eventbox#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 {CompletionProc#raise}.

Public Instance Methods

raise(*args) click to toggle source

Raise an exception in the context of the waiting {Eventbox::Boxable#yield_call 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.

# File lib/eventbox/sanitizer.rb, line 410
def raise(*args)
  self.call(WrappedException.new(args))
end