fix: transport owns WS stream lifecycle (force-cancel outbound, emit stream:error, balanced events)

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-06-27 15:40:50 -05:00
1 parent b58db71405
commit e365cee3bf
2 files changed
+21 -8

No files matched your search

-2
View File
@@ -177,13 +177,11 @@ export function createApp(opts: { modules: Ctor[]; plugins?: Plugin[] }): App {
.map((plan) => ({
pattern: plan.pattern,
open: async ({ params, inbound, abort, req }) => {
bus.emit('stream:open', { name: plan.pattern });
const provided = await providedSeed(plan);
let ctx: any = { ...provided, req, params, query: parseQuery(req.url ?? ''), body: undefined,
headers: req.headers, inbound, abort };
for (const s of planSteps(plan)) { ctx = { ...ctx, ...(await s.run(ctx)) }; }
const out = plan.run(ctx);
abort.addEventListener('abort', () => bus.emit('stream:close', { name: plan.pattern }));
if (!isAsyncIterable(out)) throw new Error(`@Ws handler '${plan.handlerName}' must return an AsyncIterable`);
return out as AsyncIterable<unknown>;
},