MCPcopy
hub / github.com/microsoft/vscode-js-debug / once

Function once

src/common/objUtils.ts:198–218  ·  view source on GitHub ↗
(
  fn: (...args: Args) => T,
)

Source from the content-addressed store, hash-verified

196 * the result.
197 */
198export function once<T, Args extends unknown[]>(
199 fn: (...args: Args) => T,
200): ((...args: Args) => T) & { value?: T; forget(): void } {
201 let value: T | typeof unset = unset;
202 const onced = (...args: Args) => {
203 if (value === unset) {
204 onced.value = value = fn(...args);
205 }
206
207 return value;
208 };
209
210 onced.forget = () => {
211 value = unset;
212 onced.value = undefined;
213 };
214
215 onced.value = undefined as T | undefined;
216
217 return onced;
218}
219
220/**
221 * Memoizes the single-parameter function.

Callers 15

BinderClass · 0.90
PackageJsonProviderClass · 0.90
provideTerminalLinksMethod · 0.90
NetworkRequestClass · 0.90
processTree.tsFile · 0.90
EnvironmentVarsClass · 0.90
win32Utils.tsFile · 0.90
listenMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected