summaryrefslogtreecommitdiff
path: root/std/node/_utils.ts
diff options
context:
space:
mode:
authorSteven Guerrero <stephenguerrero43@gmail.com>2020-11-21 16:13:18 -0500
committerGitHub <noreply@github.com>2020-11-21 16:13:18 -0500
commita4f27c4d570ad9b47bbd560fbf9b017f852fc29f (patch)
tree84b3b0111fca262932aa2be7f1ef884fc6d5ddc3 /std/node/_utils.ts
parentce890f2ae7e8b557211e8f529180d30dc44ea7b5 (diff)
feat(std/node): Add Readable Stream / Writable Stream / errors support (#7569)
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);
+ };
+}