From 8ece841314f0c2fbff1c69ee7b0f2dae42fa97b9 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 25 Oct 2024 01:12:59 +0900 Subject: [PATCH] support once listener --- ext/node/polyfills/net.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/node/polyfills/net.ts b/ext/node/polyfills/net.ts index d91d4bf534..8b598d0bfc 100644 --- a/ext/node/polyfills/net.ts +++ b/ext/node/polyfills/net.ts @@ -360,15 +360,17 @@ function _afterConnect( socket._unrefTimer(); + const connectListeners = socket.listenerCount("connect"); + const readyListeners = socket.listenerCount("ready"); + const dataListeners = socket.listenerCount("data"); + socket.emit("connect"); socket.emit("ready"); // Note: This is Deno specific logic // If there's no listener for the connect, ready, data event, // we delay the first read. This is necessary for http.request to work properly. - const connectListeners = socket.listenerCount("connect"); - const readyListeners = socket.listenerCount("ready"); - const dataListeners = socket.listenerCount("data"); + // See https://github.com/denoland/deno/pull/25470#issuecomment-2435077722 if (connectListeners === 0 && readyListeners === 0 && dataListeners === 0) { return; }