gossamer/weak_ref

Types

A JS WeakRef whose target is weakly held — the target is eligible for GC once it has no other references.

Targets must be objects (records, lists, tuples) or non-registered symbols (gossamer/symbol.new, not gossamer/symbol.for); new returns an error otherwise.

deref may continue to return Ok for some time after all other references to the target are dropped — GC timing is non-deterministic.

See WeakRef on MDN.

pub type WeakRef(target)

Values

pub fn deref(of ref: WeakRef(target)) -> Result(target, Nil)

Returns the target, or an error if it has been collected.

pub fn new(
  target: target,
) -> Result(WeakRef(target), js_error.JsError)

Returns an error if target is invalid.

Search Document