Module: Lich::Common::ScriptDeath

Defined in:
documented/common/script_death.rb

Overview

Registry of callbacks to run when a script dies.

Subsystems that keep per-script state in a global registry (e.g. the hook registries) register a cleanup here at load time, so the Script kill path iterates handlers instead of naming each subsystem and reaching into its internals. Adding a new per-script registry means registering one handler at its own load site, not editing Script#kill.

Class Method Summary collapse

Class Method Details

.on_death {|script| ... } ⇒ void

This method returns an undefined value.

Registers a cleanup callback invoked with the dying Script on death.

Yield Parameters:

  • script (Script)

    the script being torn down



22
23
24
# File 'documented/common/script_death.rb', line 22

def on_death(&block)
  @handlers << block if block
end

.run(script) ⇒ void

This method returns an undefined value.

Runs every registered handler with the dying script. A handler that raises is logged and skipped so one bad callback cannot abort kill cleanup or block sibling handlers.

Parameters:

  • script (Script)

    the script being torn down



32
33
34
35
36
37
38
# File 'documented/common/script_death.rb', line 32

def run(script)
  @handlers.each do |handler|
    handler.call(script)
  rescue StandardError => e
    Lich.log("error: ScriptDeath handler: #{e}") if defined?(Lich) && Lich.respond_to?(:log)
  end
end