moonzero · control plane v0.15.0 · 49 packages · 4 targets · Apache-2.0 docs / data / once GitHub

10 / DATA

once

A body that runs at most once, for the initialisation that must not happen twice, and a pool that builds its objects on the first take and hands them back.

struct Once

structA body that runs at most once: the first caller runs it, every later one is a no-op. Guards one-time initialisation, which in a service is a pool, a table or a connection that must not be built twice.

fn Once::new() -> Once

fnA body that has not run yet.

fn Once::done(self : Once) -> Bool

fnWhether the body has run.

fn Once::run(self : Once, body : () -> Unit) -> Bool

fnRun body unless it has already run, and report whether this call ran it.

struct Pool[T]

structA pool of reusable objects: a caller takes one, uses it, and hands it back. Building is deferred until the first take, so a pool nobody touches costs nothing — which is what makes it usable for a buffer or a connection that only some code paths need.

fn[T] Pool::new(make : () -> T) -> Pool[T]

itemA pool that builds its objects with make.

fn[T] Pool::get(self : Pool[T]) -> T

itemTake an object: an idle one when there is one, a fresh one otherwise.

fn[T] Pool::put(self : Pool[T], item : T) -> Unit

itemHand an object back. The pool keeps every one it is given, so a caller that wants a ceiling on retained objects puts one on its own side.

fn[T] Pool::idle(self : Pool[T]) -> Int32

itemHow many objects are idle.