Module sync/once

sync/once

One-time initialization primitive.

Example

{ Once } :: import "std/sync/once";

init := Once.new();
// Only the first call executes the function
init.call(() => {
  println("initialized!");
});
init.call(() => {
  println("this will NOT run");
});

Types

Once atomic object
Once

Execute a function exactly once, thread-safely. Uses atomic reference counting for safe cross-thread sharing.

Fields

NameTypeDescription
_donebool
_mutexMutex
impl(Once, ...)
new : (Once) fn() -> Once

Returns: Once

call : (Once) fn(self : Once, f : Impl(Fn() -> unit)) -> unit

Parameters

NameTypeNotes
selfOnce
fImpl(Fn() -> unit)

Returns: unit

is_done : (Once) fn(self : Once) -> bool

Parameters

NameTypeNotes
selfOnce

Returns: bool