menu

AsyncOnceCell

import { AsyncOnceCell } from "destack:async";

One-time async initialized cell.

language/library/src/async/once.ds:21:44
1export class AsyncOnceCell<T> {2    value: MaybeUninit<T>;3    get(): &readonly T | undefined;4    set(value: ^T): Result<void, ^T>;5    getOrInit(init: () => Task<T>): Task<&readonly T>;6    take(): T | undefined;7}

Members

value: MaybeUninit<T>

The stored value.

get(): &readonly T | undefined

Get the initialized value.

set(value: ^T): Result<void, ^T>

Set the value once.

getOrInit(init: () => Task<T>): Task<&readonly T>

Get the value or initialize it.

take(): T | undefined

Move the value out when initialized.