Returns a wrapper that calls fn only on the first invocation. All subsequent calls return the cached result of the first call.
fn
The function to wrap.
const init = once(() => createConnection())init() // creates connectioninit() // returns cached connection Copy
const init = once(() => createConnection())init() // creates connectioninit() // returns cached connection
Returns a wrapper that calls
fnonly on the first invocation. All subsequent calls return the cached result of the first call.