Cleanup
This commit is contained in:
@@ -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")))
|
||||
})
|
||||
}),
|
||||
))
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import { ServerConfig } from "./ServerConfig"
|
||||
import { Services } from "./Services"
|
||||
import { ExpressApp } from "./http/ExpressApp"
|
||||
import { ExpressHTTPServer } from "./http/ExpressHTTPServer"
|
||||
import { WebSocketServer } from "./http/WebSocketServer"
|
||||
import { RPCPlaygroundRoute } from "./rpc/RPCPlaygroundRoute"
|
||||
import { RPCRoute } from "./rpc/RPCRoute"
|
||||
import { RPCRouter } from "./rpc/RPCRouter"
|
||||
@@ -40,7 +39,6 @@ const ServerLive = Layer.empty.pipe(
|
||||
Layer.provideMerge(TRPCBuilder.Live),
|
||||
Layer.provideMerge(TRPCContextCreator.Live),
|
||||
|
||||
Layer.provideMerge(WebSocketServer.Live),
|
||||
Layer.provideMerge(ExpressHTTPServer.Live),
|
||||
Layer.provideMerge(ExpressApp.Live),
|
||||
)
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import { applyWSSHandler } from "@trpc/server/adapters/ws"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { WebSocketServer } from "../http/WebSocketServer"
|
||||
import { TRPCContextCreator } from "../trpc/TRPCContextCreator"
|
||||
import { RPCRouter } from "./RPCRouter"
|
||||
|
||||
|
||||
export module RPCWebSocketHandler {
|
||||
export const Live = Layer.effectDiscard(Effect.acquireRelease(
|
||||
Effect.gen(function*() {
|
||||
return applyWSSHandler({
|
||||
wss: yield* WebSocketServer,
|
||||
router: yield* RPCRouter,
|
||||
createContext: (yield* TRPCContextCreator).createWebSocketContext,
|
||||
})
|
||||
}),
|
||||
|
||||
handler => Effect.sync(() =>
|
||||
handler.broadcastReconnectNotification()
|
||||
),
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user