MCPcopy Create free account
hub / github.com/Snapchat/Valdi / once

Function once

valdi/vscode_debugger/src/common/objUtils.ts:190–210  ·  view source on GitHub ↗
(
  fn: (...args: Args) => T,
)

Source from the content-addressed store, hash-verified

188 * the result.
189 */
190export function once<T, Args extends unknown[]>(
191 fn: (...args: Args) => T,
192): ((...args: Args) => T) & { value?: T; forget(): void } {
193 let value: T | typeof unset = unset;
194 const onced = (...args: Args) => {
195 if (value === unset) {
196 onced.value = value = fn(...args);
197 }
198
199 return value;
200 };
201
202 onced.forget = () => {
203 value = unset;
204 onced.value = undefined;
205 };
206
207 onced.value = undefined as T | undefined;
208
209 return onced;
210}
211
212/**
213 * Memoizes the single-parameter function.

Callers 9

findBrowserPathMethod · 0.90
findBrowserPathMethod · 0.90
BrowserArgsClass · 0.90
VueFileMapperClass · 0.90
constructorMethod · 0.90
RawPipeTransportClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected