The type parameter. The actual stored type is Awaited<T>.
Readonly[toThe well-known symbol Symbol.toStringTag used by Object.prototype.toString().
Returns 'OnceAsync' so that Object.prototype.toString.call(once) produces '[object OnceAsync]'.
Gets the contents, initializing it with async fn if empty.
If multiple calls occur concurrently, only the first one will run the initialization function. Other calls will wait for it to complete.
A promise that resolves to the stored value (Awaited<T>).
Gets the contents, initializing it with async fn if empty.
If fn returns Err, remains uninitialized.
If multiple calls occur concurrently, only the first one will run the initialization function. Other calls will wait for it to complete.
The error type.
A promise that resolves to Ok(value) or Err(error).
Sets the contents to value.
The value to store.
Ok(undefined) if empty, Err(value) if already initialized.
Sets the contents to value if empty, returning a reference to the value.
Unlike set(), this method returns the stored value on success,
and returns both the current and passed values on failure.
The value to store.
Ok(value) if empty, Err([currentValue, passedValue]) if already initialized.
Waits for the cell to be initialized, then returns the value.
If the cell is already initialized, returns immediately. If initialization is in progress, waits for it to complete. If the cell is uninitialized and no initialization is in progress, the returned promise will resolve when another caller initializes the cell.
A promise that resolves to the stored value once initialized.
An async-first container which can be written to only once.
OnceAsync<T>storesAwaited<T>, matching JavaScript's Promise flattening behavior. This meansOnceAsync<Promise<number>>andOnceAsync<number>behave identically, both storingnumber.Key difference from
Once<T>:Once<T>with sync methods storesTas-is (including Promise values)OnceAsync<T>always storesAwaited<T>(flattened value)Since
1.8.0
See
Once for sync-only one-time initialization
Example
Example