方法
- C
- R
- T
- W
包含的模块
类公共方法
register_hook(hook, outer: false) 链接
注册一个对象,该对象将在 `run` 和 `complete` 步骤中被调用。
`hook.complete` 将接收 `hook.run` 返回的值,并且仅当 `run` 之前已调用时才会调用。 (这主要意味着,如果在前面的 to_run 块中发生异常,则不会调用它;在这种情况下,所有普通的 to_complete 块都会被调用。)
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/execution_wrapper.rb, line 50 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
run!(reset: false) 链接
运行此执行。
返回一个实例,其 `complete!` 方法在工作完成后 **必须** 被调用。
在可能的情况下,请优先使用 `wrap`。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/execution_wrapper.rb, line 66 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
to_complete(*args, &block) 链接
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/execution_wrapper.rb, line 21 def self.to_complete(*args, &block) set_callback(:complete, *args, &block) end
to_run(*args, &block) 链接
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/execution_wrapper.rb, line 17 def self.to_run(*args, &block) set_callback(:run, *args, &block) end
wrap(source: "application.active_support") 链接
将提供的块中的工作作为一个执行来执行。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/execution_wrapper.rb, line 86 def self.wrap(source: "application.active_support") return yield if active? instance = run! begin yield rescue Exception => error error_reporter&.report(error, handled: false, source: source) raise ensure instance.complete! end end
实例公共方法
complete!() 链接
完成此正在进行的执行。此方法 **必须** 对任何对 `run!` 的调用结果调用一次。
在可能的情况下,请优先使用 `wrap`。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/execution_wrapper.rb, line 135 def complete! complete ensure IsolatedExecutionState.delete(self.class.active_key) end