gossamer/finalization_registry
Types
A JS FinalizationRegistry that fires cleanup callbacks after
registered targets are garbage collected. Callback timing is
non-deterministic — callbacks may fire late, or not at all if the
program exits before GC runs. Errors thrown from the callback are
reported to the runtime, not to surrounding code.
Targets and unregister tokens must be objects (records, lists,
tuples) or non-registered symbols (gossamer/symbol.new, not
gossamer/symbol.for); register, register_with_token, and
unregister return an error otherwise.
Unregister tokens are matched by JS reference identity — pass the
same JS reference to unregister that was passed to
register_with_token.
See FinalizationRegistry on MDN.
pub type FinalizationRegistry(held)
Values
pub fn new(callback: fn(held) -> a) -> FinalizationRegistry(held)
pub fn register(
in registry: FinalizationRegistry(held),
target target: target,
held held: held,
) -> Result(FinalizationRegistry(held), js_error.JsError)
Registers target for cleanup, passing held to the callback when
it runs. Mutates the registry. Returns an error if target is
invalid.
pub fn register_with_token(
in registry: FinalizationRegistry(held),
target target: target,
held held: held,
unregister_token token: token,
) -> Result(FinalizationRegistry(held), js_error.JsError)
Registers target for cleanup with an unregister_token that can
later be passed to unregister to remove the registration. Mutates
the registry. Returns an error if target or unregister_token
is invalid.
pub fn unregister(
from registry: FinalizationRegistry(held),
unregister_token token: token,
) -> Result(FinalizationRegistry(held), js_error.JsError)
Removes all registrations associated with unregister_token.
Mutates the registry. Returns an error if unregister_token is
invalid.