方法
- 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 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
run!(reset: false) 連結
執行此執行。
傳回一個執行個體,其 complete!
方法必須在執行工作後呼叫。
如果可以,請優先使用 wrap
。
來源:顯示 | 在 GitHub 上
# 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
to_complete(*args, &block) 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/execution_wrapper.rb, line 22 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 18 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 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
執行個體公開方法
complete!() 連結
完成此進行中的執行。此方法必須在任何呼叫 run!
的結果上呼叫一次。
如果可以,請優先使用 wrap
。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/execution_wrapper.rb, line 136 def complete! complete ensure IsolatedExecutionState.delete(self.class.active_key) end