UNPKG

614 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.once = once;
4/**
5 * Function wrapper to ensure a function/callback is only called once.
6 *
7 * @group Utils
8 */
9// eslint-disable-next-line @typescript-eslint/ban-types
10function once(func) {
11 let called = false;
12 return ((...args) => {
13 if (called) {
14 throw new Error("This callback function has already been called by someone else; it can only be called one time.");
15 }
16 else {
17 called = true;
18 return func(...args);
19 }
20 });
21}
22//# sourceMappingURL=once.js.map
\No newline at end of file