UNPKG

@apptus/esales-api

Version:

Library for making requests to Elevate 4 API v3

17 lines (15 loc) 456 B
/** * Only ever execute the supplied function once. Subsequent calls * will return the value from the first invocation. */ export function once<T extends (...args: unknown[]) => 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; }