Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: http response stream not interruptible #3922

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/platform-node/examples/http-tag-router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpMiddleware, HttpRouter, HttpServer, HttpServerResponse } from "@effect/platform"
import { NodeHttpServer, NodeRuntime } from "@effect/platform-node"
import { Effect, Layer } from "effect"
import { Effect, Layer, PubSub, Stream } from "effect"
import { createServer } from "http"

// You can define router instances using `HttpRouter.Tag`
Expand All @@ -9,7 +9,14 @@ class UserRouter extends HttpRouter.Tag("UserRouter")<UserRouter>() {}
// Create `Layer`'s for your routes with `UserRouter.use`
const GetUsers = UserRouter.use((router) =>
Effect.gen(function*() {
const ps = yield* PubSub.unbounded<Uint8Array>()
// the following would work, but why doesn't the http server interrupt the stream reading?
// yield* Effect.addFinalizer(() => ps.shutdown)
yield* router.get("/", HttpServerResponse.text("got users"))
yield* router.get(
"/stream",
Stream.fromPubSub(ps, { scoped: true }).pipe(Effect.map(HttpServerResponse.stream))
)
})
)

Expand Down Expand Up @@ -41,4 +48,5 @@ const HttpLive = HttpRouter.Default.unwrap(HttpServer.serve(HttpMiddleware.logge
Layer.provide(ServerLive)
)

console.log("pid", process.pid)
NodeRuntime.runMain(Layer.launch(HttpLive))