Class: Eventbox::ExternalProc
- Inherits:
-
WrappedProc
- Object
- Proc
- WrappedProc
- Eventbox::ExternalProc
- Defined in:
- lib/eventbox/sanitizer.rb
Overview
Wrapper for Proc objects created external or in the action scope of some Eventbox instance.
External Proc objects can be invoked from event scope by ExternalProc#call. It can be called within sync_call and yield_call methods and from #sync_proc and #yield_proc closures. The proc then runs in the background on the thread that called the event scope method in execution.
It’s also possible to invoke it within a async_call or #async_proc, when the method or proc that brought the external proc into the event scope, is a yield call that didn’t return yet. In this case the proc runs in the background on the thread that is waiting for the yield call to return.
Optionally a proc can be provided as the last argument which acts as a completion callback. This proc is invoked, when the call has finished, with the result value as argument.
class Callback < Eventbox
sync_call def init(&block)
# invoke the block given to Callback.new
# and when completed, print the result of the block
block.call 5, ->(res){ p res }
end
end
Callback.new {|num| num + 1 } # Output: 6
External Proc objects can also be passed to action or to external scope. In this case a ExternalProc is unwrapped back to the ordinary Proc object.