Methods
Included Modules
Class Public methods
register_hook(hook, outer: false)
Register an object to be invoked during both the run
and complete
steps.
hook.complete
will be passed the value returned from hook.run
, and will only be invoked if run
has previously been called. (Mostly, this means it wonβt be invoked if an exception occurs in a preceding to_run
block; all ordinary to_complete
blocks are invoked in that situation.)
π Source code
# File activesupport/lib/active_support/execution_wrapper.rb, line 51
def self.register_hook(hook, outer: false)
if outer
to_run RunHook.new(hook), prepend: true
to_complete :after, CompleteHook.new(hook)
else
to_run RunHook.new(hook)
to_complete CompleteHook.new(hook)
end
end
π See on GitHub
run!(reset: false)
Run this execution.
Returns an instance, whose complete!
method must be invoked after the work has been performed.
Where possible, prefer wrap
.
π Source code
# File activesupport/lib/active_support/execution_wrapper.rb, line 67
def self.run!(reset: false)
if reset
lost_instance = IsolatedExecutionState.delete(active_key)
lost_instance&.complete!
else
return Null if active?
end
new.tap do |instance|
success = nil
begin
instance.run!
success = true
ensure
instance.complete! unless success
end
end
end
π See on GitHub
to_complete(*args, &block)
π Source code
# File activesupport/lib/active_support/execution_wrapper.rb, line 22
def self.to_complete(*args, &block)
set_callback(:complete, *args, &block)
end
π See on GitHub
to_run(*args, &block)
π Source code
# File activesupport/lib/active_support/execution_wrapper.rb, line 18
def self.to_run(*args, &block)
set_callback(:run, *args, &block)
end
π See on GitHub
wrap(source: "application.active_support")
Perform the work in the supplied block as an execution.
π Source code
# File activesupport/lib/active_support/execution_wrapper.rb, line 87
def self.wrap(source: "application.active_support")
return yield if active?
instance = run!
begin
yield
rescue => error
error_reporter&.report(error, handled: false, source: source)
raise
ensure
instance.complete!
end
end
π See on GitHub
Instance Public methods
complete!()
Complete this in-flight execution. This method must be called exactly once on the result of any call to run!
.
Where possible, prefer wrap
.
π Source code
# File activesupport/lib/active_support/execution_wrapper.rb, line 136
def complete!
complete
ensure
IsolatedExecutionState.delete(self.class.active_key)
end
π See on GitHub