# OnceCell

`import { OnceCell } from "destack:sync";`

One-time initialized cell.

```ds title="OnceCell"
export class OnceCell<T> {
    state: Atomic<uint32>;
    value: MaybeUninit<T>;
    get(): &readonly T | undefined;
    set(value: ^T): Result<void, ^T>;
    getOrInit(init: () => T): &readonly T;
    take(): T | undefined;
}
```

[language/library/src/sync/once.ds:23:49](https://github.com/destack-sh/destack/blob/main/language/library/src/sync/once.ds#L23-L49)

## Members

### `state: Atomic<uint32>`

The initialization state.

### `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: () => T): &readonly T`

Get the value or initialize it.

### `take(): T | undefined`

Move the value out when initialized.
