From a4f27c4d570ad9b47bbd560fbf9b017f852fc29f Mon Sep 17 00:00:00 2001 From: Steven Guerrero Date: Sat, 21 Nov 2020 16:13:18 -0500 Subject: feat(std/node): Add Readable Stream / Writable Stream / errors support (#7569) --- std/node/_utils.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'std/node/_utils.ts') 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 extends undefined ? [] + : [T]; + +export function once(callback: (...args: OptionalSpread) => void) { + let called = false; + return function (this: unknown, ...args: OptionalSpread) { + if (called) return; + called = true; + callback.apply(this, args); + }; +} -- cgit v1.2.3