History

nits

Julius Marminge committed 8 months ago

Commit 5a755ad1 parent b211d053 files · +33 −29Browse files

Showing the changes to apps/server/src/wsServer.ts (1 of 3 files). Show all

Unified · Split

apps/server/src/wsServer.ts+30−27
@@ -183,23 +183,22 @@ export const createServer = Effect.fn(function* (options: ServerOptions = {}): E · 182 unmodified lines
183183 });
184184 }
185185
186− const onTerminalEvent = (event: TerminalEvent) =>
187− Effect.gen(function* () {
188− const push: WsPush = {
189− type: "push",
190− channel: WS_CHANNELS.terminalEvent,
191− data: event,
192− };
193− const message = yield* Schema.encodeEffect(Schema.fromJsonString(WsPush))(push);
194− let recipients = 0;
195− for (const client of yield* Ref.get(clients)) {
196− if (client.readyState === client.OPEN) {
197− client.send(message);
198− recipients += 1;
199− }
186+ const onTerminalEvent = Effect.fnUntraced(function* (event: TerminalEvent) {
187+ const push: WsPush = {
188+ type: "push",
189+ channel: WS_CHANNELS.terminalEvent,
190+ data: event,
191+ };
192+ const message = yield* Schema.encodeEffect(Schema.fromJsonString(WsPush))(push);
193+ let recipients = 0;
194+ for (const client of yield* Ref.get(clients)) {
195+ if (client.readyState === client.OPEN) {
196+ client.send(message);
197+ recipients += 1;
200198 }
201− logOutgoingPush(push, recipients);
202− }).pipe(Effect.runPromise);
199+ }
200+ logOutgoingPush(push, recipients);
201+ });
203202
204203 // HTTP server — serves static files or redirects to Vite dev server
205204 const httpServer = http.createServer((req, res) => {
@@ -289,9 +288,7 @@ export const createServer = Effect.fn(function* (options: ServerOptions = {}): E · 83 unmodified lines
289288 const { openInEditor } = yield* Open;
290289
291290 const subscriptionsScope = yield* Scope.make("sequential");
292− yield* Effect.addFinalizer(() =>
293− Scope.close(subscriptionsScope, Exit.void).pipe(Effect.orElseSucceed(() => undefined)),
294− );
291+ yield* Effect.addFinalizer(() => Scope.close(subscriptionsScope, Exit.void));
295292
296293 yield* Stream.runForEach(orchestrationEngine.streamDomainEvents, (event) =>
297294 Effect.gen(function* () {
@@ -312,7 +309,7 @@ export const createServer = Effect.fn(function* (options: ServerOptions = {}): E · 14 unmodified lines
312309 }),
313310 ).pipe(Effect.forkIn(subscriptionsScope));
314311
315− yield* orchestrationReactor.start.pipe(Scope.provide(subscriptionsScope));
312+ yield* Scope.provide(orchestrationReactor.start, subscriptionsScope);
316313
317314 if (autoBootstrapProjectFromCwd) {
318315 const snapshot = yield* projectionReadModelQuery.getSnapshot();
@@ -332,7 +329,7 @@ export const createServer = Effect.fn(function* (options: ServerOptions = {}): E · 13 unmodified lines
332329 }
333330 }
334331
335− const routeRequest = Effect.fn(function* (request: WebSocketRequest) {
332+ const routeRequest = Effect.fnUntraced(function* (request: WebSocketRequest) {
336333 switch (request.body._tag) {
337334 case ORCHESTRATION_WS_METHODS.getSnapshot:
338335 return yield* projectionReadModelQuery.getSnapshot();
@@ -573,18 +570,24 @@ export const createServer = Effect.fn(function* (options: ServerOptions = {}): E · 234 unmodified lines
573570 ),
574571 );
575572
576− const unsubscribeTerminalEvents = yield* terminalManager.subscribe(onTerminalEvent);
573+ const unsubscribeTerminalEvents = yield* terminalManager.subscribe(
574+ (event) => void Effect.runPromise(onTerminalEvent(event)),
575+ );
577576 yield* Effect.addFinalizer(() =>
578− Effect.sync(() => {
579− unsubscribeTerminalEvents();
580− }),
577+ Effect.all([Effect.sync(() => unsubscribeTerminalEvents()), terminalManager.dispose()]),
581578 );
582− yield* Effect.addFinalizer(terminalManager.dispose);
583579
584580 yield* NodeHttpServer.make(() => httpServer, listenOptions);
585581
586582 yield* Effect.addFinalizer(() =>
587− Effect.all([closeAllClients, closeWebSocketServer.pipe(Effect.orElseSucceed(() => undefined))]),
583+ Effect.all([
584+ closeAllClients,
585+ closeWebSocketServer.pipe(
586+ Effect.catch((error) =>
587+ Effect.logWarning("failed to close web socket server", { cause: error }),
588+ ),
589+ ),
590+ ]),
588591 );
589592
590593 return httpServer;