Creates a function that executes only once. Subsequent calls return the cached result. Similar to memoize but doesn't consider arguments - always returns the same result.
The return type of the function.
The async task to execute once.
Optional
Cancellable configuration options.
A function that returns a cancellable handle, executing only on first call.
let count = 0;const initialize = once(async () => { count++; return "initialized";});await initialize(); // count = 1, returns "initialized"await initialize(); // count = 1, returns "initialized" (cached) Copy
let count = 0;const initialize = once(async () => { count++; return "initialized";});await initialize(); // count = 1, returns "initialized"await initialize(); // count = 1, returns "initialized" (cached)
Creates a function that executes only once. Subsequent calls return the cached result. Similar to memoize but doesn't consider arguments - always returns the same result.