Ensures an asynchronous function is executed only once.
Subsequent calls return the same pending or resolved promise from the first invocation.
The async function type.
The asynchronous function to execute only once.
A wrapped function that runs fn once and caches the promise.
fn
const init = onceAsync(async () => { console.log("Initializing..."); await new Promise(r => setTimeout(r, 1000)); return "ready";});await init(); // Logs "Initializing..."await init(); // Returns cached promise, no log Copy
const init = onceAsync(async () => { console.log("Initializing..."); await new Promise(r => setTimeout(r, 1000)); return "ready";});await init(); // Logs "Initializing..."await init(); // Returns cached promise, no log
1.2.0
Ensures an asynchronous function is executed only once.
Subsequent calls return the same pending or resolved promise from the first invocation.