Effect CommunityEC
Effect Community2y ago
11 replies
Patrick Roza

Update to HTTP Client in Node Platform Package: Removal of AbortSignal Creation

tim?
diff --git a/packages/platform-node/src/internal/http/clientUndici.ts b/packages/platform-node/src/internal/http/clientUndici.ts
index ba0764dd3..9070117b1 100644
--- a/packages/platform-node/src/internal/http/clientUndici.ts
+++ b/packages/platform-node/src/internal/http/clientUndici.ts
@@ -35,14 +35,6 @@ export const dispatcherLayer = Layer.scoped(Dispatcher, makeDispatcher)
 /** @internal */
 export const dispatcherLayerGlobal = Layer.sync(Dispatcher, () => Undici.getGlobalDispatcher())
 
-const makeAbortSignal = Effect.map(
-  Effect.acquireRelease(
-    Effect.sync(() => new AbortController()),
-    (controller) => Effect.sync(() => controller.abort())
-  ),
-  (_) => _.signal
-)
-
 /** @internal */
 export const make = (dispatcher: Undici.Dispatcher): Client.Client.Default =>
   Client.makeDefault((request) =>
@@ -55,10 +47,9 @@ export const make = (dispatcher: Undici.Dispatcher): Client.Client.Default =>
             error: _
           }))),
       Effect.bind("body", () => convertBody(request.body)),
-      Effect.bind("signal", () => makeAbortSignal),
-      Effect.flatMap(({ body, signal, url }) =>
+      Effect.flatMap(({ body, url }) =>
         Effect.tryPromise({
-          try: () =>
+          try: (signal) =>
             dispatcher.request({
               signal,
               method: request.method,
diff --git a/packages/platform/src/internal/http/client.ts b/packages/platform/src/internal/http/client.ts
index f06fd5ac6..6298cdd93 100644
--- a/packages/platform/src/internal/http/client.ts
+++ b/packages/platform/src/internal/http/client.ts
@@ -131,29 +131,23 @@ export const fetch = (options?: RequestInit): Client.Client.Default =>
         const headers = new Headers(request.headers)
         const send = (body: BodyInit | undefined) =>
           pipe(
-            Effect.acquireRelease(
-              Effect.sync(() => new AbortController()),
-              (controller) => Effect.sync(() => controller.abort())
-            ),
-            Effect.flatMap((controller) =>
-              Effect.tryPromise({
-                try: () =>
-                  fetch(url, {
-                    ...options,
-                    method: request.method,
-                    headers,
-                    body,
-                    duplex: request.body._tag === "Stream" ? "half" : undefined,
-                    signal: controller.signal
-                  } as any),
-                catch: (_) =>
-                  new Error.RequestError({
-                    request,
-                    reason: "Transport",
-                    error: _
-                  })
-              })
-            ),
+            Effect.tryPromise({
+              try: (signal) =>
+                fetch(url, {
+                  ...options,
+                  method: request.method,
+                  headers,
+                  body,
+                  duplex: request.body._tag === "Stream" ? "half" : undefined,
+                  signal
+                } as any),
+              catch: (_) =>
+                new Error.RequestError({
+                  request,
+                  reason: "Transport",
+                  error: _
+                })
+            }),
             Effect.map((_) => internalResponse.fromWeb(request, _))
           )
         if (Method.hasBody(request.method)) {
Was this page helpful?