summaryrefslogtreecommitdiff
path: root/std/node/_utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/node/_utils.ts')
-rw-r--r--std/node/_utils.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/std/node/_utils.ts b/std/node/_utils.ts
index b2745bf5a..cb91fac27 100644
--- a/std/node/_utils.ts
+++ b/std/node/_utils.ts
@@ -131,3 +131,15 @@ export function validateIntegerRange(
);
}
}
+
+type OptionalSpread<T> = T extends undefined ? []
+ : [T];
+
+export function once(callback: (...args: OptionalSpread<undefined>) => void) {
+ let called = false;
+ return function (this: unknown, ...args: OptionalSpread<undefined>) {
+ if (called) return;
+ called = true;
+ callback.apply(this, args);
+ };
+}