/** * Only ever execute the supplied function once. Subsequent calls * will return the value from the first invocation. */ export function once unknown>(method: T): T { let executed = false; let returnValue: unknown; return function onceInner(this: unknown, ...args: unknown[]) { if (!executed) { executed = true; returnValue = method.apply(this, args); } return returnValue; } as T; }