Add transport-neutral routing and stream contracts

This commit is contained in:
2026-07-27 09:31:35 +00:00
parent c0a8936828
commit e4ceacade8
7 changed files with 426 additions and 2 deletions
+45
View File
@@ -0,0 +1,45 @@
import {
BaseStream,
type StreamMessage,
} from "../../src/services/stream/base-stream.js";
/** Minimal observable connection used by application and broadcaster tests. */
export class TestConnection extends BaseStream {
readonly messages: StreamMessage[] = [];
readonly closeCallbacks: Array<() => void> = [];
closed = false;
constructor(
readonly streaming: boolean,
readonly bidirectional: boolean,
) {
super();
}
async send(message: StreamMessage): Promise<void> {
if (this.closed) {
throw new Error("connection is closed");
}
this.messages.push(message);
}
close(): void {
if (this.closed) {
return;
}
this.closed = true;
const callbacks = this.closeCallbacks.splice(0);
callbacks.forEach((callback) => callback());
}
onClose(callback: () => void): void {
if (this.closed) {
callback();
return;
}
this.closeCallbacks.push(callback);
}
}