This commit is contained in:
Julien Valverdé
2024-07-17 05:15:01 +02:00
parent a0bf11466d
commit c3560c41bc
5 changed files with 2 additions and 48 deletions

View File

@@ -1,22 +0,0 @@
import { Context, Effect, Layer } from "effect"
import ws from "ws"
import { ExpressHTTPServer } from "../http/ExpressHTTPServer"
export class WebSocketServer extends Context.Tag("WebSocketServer")<WebSocketServer, ws.Server>() {}
export module WebSocketServer {
export const Live = Layer.effect(WebSocketServer, Effect.acquireRelease(
Effect.gen(function*() {
yield* Effect.logInfo("WebSocket server started")
return new ws.WebSocketServer({ server: yield* ExpressHTTPServer })
}),
wss => Effect.gen(function*() {
yield* Effect.logInfo("WebSocket server is stopping. Waiting for existing connections to end...")
yield* Effect.async(resume => {
wss.close(() => resume(Effect.logInfo("WebSocket server closed")))
})
}),
))
}