modules.on_module_unload
Defined in module
"modules"from "modules" import on_module_unloadRegister module unload callback. Example: on_module_unload( function(is_app_closing) {println(is_app_closing ? "Closing" : "Soft reloading")} )
This function is bound with a type mask instead of a declaration string. The VM cannot report parameter names, and cannot tell an optional parameter from a variadic tail, so the brackets and the trailing
... above are not evidence either way.Parameters
arg1 | function | arg1([is_app_closing]), the callback to run. This function is bound with a type mask instead of a declaration string, so the VM cannot report the real parameter name; arg1 is the callback, not a value passed to it. |
Return value
null.
Errors
Throws when the callback takes more than one argument (besides this): a registered callback must accept zero or one argument.
Notes
The callback runs later, not immediately: once when the module manager is destroyed (typically at process exit), with is_app_closing set to true, and also once before a hot reload of a module or of all modules, with is_app_closing set to false. Callbacks run in the order they were registered.
Registering the exact same function object a second time has no extra effect: only one call happens per distinct callback, however many times it was registered.
Example
let modules = require("modules")
// Runs when this script's module manager is torn down: normally at process
// exit, or before a script is hot-reloaded during development.
modules.on_module_unload(function(is_app_closing) {
println($"unload, is_app_closing={is_app_closing}")
})
println("script body done")
// Nothing else to do: the callback above fires after this, when the host
// closes the VM, so its output always comes last.Output:
script body done
unload, is_app_closing=trueSee also
get_native_module_names | Returns an array with a list of names of native modules. |
reset_static_memos | Reset static memo expressions cache. |
| modules | module index |