Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

fix server interrupt #25

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/curly-jeans-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/experimental": patch
---

fix server interrupt
17 changes: 7 additions & 10 deletions src/DevTools/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,8 @@ export const make = Effect.gen(function*(_) {

const handle = (socket: Socket.Socket) =>
Effect.gen(function*(_) {
const responses = yield* _(Effect.acquireRelease(
Queue.unbounded<Domain.Response>(),
Queue.shutdown
))
const requests = yield* _(Effect.acquireRelease(
Queue.unbounded<Domain.Span>(),
Queue.shutdown
))
const responses = yield* _(Queue.unbounded<Domain.Response>())
const requests = yield* _(Queue.unbounded<Domain.Span>())

yield* _(clients.offer(requests))

Expand All @@ -69,10 +63,13 @@ export const make = Effect.gen(function*(_) {
req._tag === "Ping"
? responses.offer({ _tag: "Pong" })
: requests.offer(req)
)
),
Effect.ensuring(Effect.all([
requests.shutdown,
responses.shutdown
]))
)
}).pipe(
Effect.scoped,
Effect.catchAllCause(Effect.log),
Effect.fork
)
Expand Down
8 changes: 4 additions & 4 deletions src/SocketServer/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export const make = (
)
})
server.listen(options)
return Effect.async<never, never, void>((resume) => {
return Effect.sync(() => {
serverDeferred = Deferred.unsafeMake(fiberId)
server.removeAllListeners()
server.close(() => resume(Effect.unit))
server.close()
})
}).pipe(
semaphore.withPermits(1)
Expand Down Expand Up @@ -159,10 +159,10 @@ export const makeWebSocket = (
Effect.runFork
)
})
return Effect.async<never, never, void>((resume) => {
return Effect.sync(() => {
serverDeferred = Deferred.unsafeMake(fiberId)
server.removeAllListeners()
server.close(() => resume(Effect.unit))
server.close()
})
}).pipe(
semaphore.withPermits(1)
Expand Down
Loading