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

Commit

Permalink
fix server interrupt (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Dec 10, 2023
1 parent 523005f commit e8d5e6d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
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

0 comments on commit e8d5e6d

Please sign in to comment.