From a337704ceae0d15017d9e9c2b13609b3cb807c5b Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 18 Dec 2023 10:40:46 +1300 Subject: [PATCH] fix interruption --- .../src/internal/workerRunner.ts | 2 +- .../platform-node/src/internal/http/server.ts | 23 ++++++++----------- packages/platform-node/src/internal/stream.ts | 2 +- packages/platform/src/Http/Router.ts | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/platform-browser/src/internal/workerRunner.ts b/packages/platform-browser/src/internal/workerRunner.ts index 120e91d3..9d4ce831 100644 --- a/packages/platform-browser/src/internal/workerRunner.ts +++ b/packages/platform-browser/src/internal/workerRunner.ts @@ -2,7 +2,7 @@ import * as Runtime from "@effect/platform/Runtime" import { WorkerError } from "@effect/platform/WorkerError" import * as Runner from "@effect/platform/WorkerRunner" import type * as Schema from "@effect/schema/Schema" -import { Cause } from "effect" +import * as Cause from "effect/Cause" import * as Effect from "effect/Effect" import * as Layer from "effect/Layer" import * as Queue from "effect/Queue" diff --git a/packages/platform-node/src/internal/http/server.ts b/packages/platform-node/src/internal/http/server.ts index 7bbab1e1..d6bce70d 100644 --- a/packages/platform-node/src/internal/http/server.ts +++ b/packages/platform-node/src/internal/http/server.ts @@ -13,7 +13,7 @@ import type * as Path from "@effect/platform/Path" import * as Cause from "effect/Cause" import * as Config from "effect/Config" import * as Effect from "effect/Effect" -import type { LazyArg } from "effect/Function" +import { type LazyArg } from "effect/Function" import * as Layer from "effect/Layer" import * as Option from "effect/Option" import * as Runtime from "effect/Runtime" @@ -71,18 +71,15 @@ export const make = ( port: address.port }, serve: (httpApp, middleware) => - Effect.asUnit( - Effect.acquireRelease( - Effect.tap(makeHandler(httpApp, middleware!), (handler) => - Effect.sync(() => { - server.on("request", handler) - })), - (handler) => - Effect.sync(() => { - server.off("request", handler) - }) - ) - ) + Effect.gen(function*(_) { + const handler = yield* _(makeHandler(httpApp, middleware!)) + yield* _(Effect.addFinalizer(() => + Effect.sync(() => { + server.off("request", handler) + }) + )) + server.on("request", handler) + }) }) }).pipe( Effect.locally( diff --git a/packages/platform-node/src/internal/stream.ts b/packages/platform-node/src/internal/stream.ts index 56bfb235..cf9ba540 100644 --- a/packages/platform-node/src/internal/stream.ts +++ b/packages/platform-node/src/internal/stream.ts @@ -1,5 +1,5 @@ import type { SizeInput } from "@effect/platform/FileSystem" -import type { Cause } from "effect" +import type * as Cause from "effect/Cause" import * as Channel from "effect/Channel" import * as Chunk from "effect/Chunk" import * as Effect from "effect/Effect" diff --git a/packages/platform/src/Http/Router.ts b/packages/platform/src/Http/Router.ts index a6b63f29..0f681e0b 100644 --- a/packages/platform/src/Http/Router.ts +++ b/packages/platform/src/Http/Router.ts @@ -3,12 +3,12 @@ */ import type * as ParseResult from "@effect/schema/ParseResult" import type * as Schema from "@effect/schema/Schema" -import type { Scope } from "effect" import type * as Cause from "effect/Cause" import type * as Chunk from "effect/Chunk" import type * as Context from "effect/Context" import type * as Effect from "effect/Effect" import type * as Option from "effect/Option" +import type * as Scope from "effect/Scope" import * as internal from "../internal/http/router.js" import type * as App from "./App.js" import type * as Method from "./Method.js"