MCPcopy Create free account
hub / github.com/commandoperator/cmdop-sdk / FrameQueue

Class FrameQueue

node/src/transport.ts:53–104  ·  view source on GitHub ↗

* A bounded push→pull async-iterator: bridges the demux's push of frames into a * `for await` consumer (the canonical "queueable" pattern, report 11 §1.4).

Source from the content-addressed store, hash-verified

51 }
52
53 end(): void {
54 this.#done = true;
55 this.#wakeDone();
56 }
57
58 fail(error: Error): void {
59 this.#error = error;
60 this.#done = true;
61 this.#wakeDone();
62 }
63
64 #wakeDone(): void {
65 if (this.#wait) {
66 const waiter = this.#wait;
67 this.#wait = undefined;
68 waiter({ value: undefined as never, done: true });
69 }
70 }
71
72 async *iterate(): AsyncGenerator<Envelope> {
73 for (;;) {
74 if (this.#error) throw this.#error;
75 if (this.#frames.length) {
76 yield this.#frames.shift()!;
77 continue;
78 }
79 if (this.#done) return;
80 const result = await new Promise<IteratorResult<Envelope>>((resolve) => {
81 this.#wait = resolve;
82 });
83 if (this.#error) throw this.#error;
84 if (result.done) return;
85 yield result.value;
86 }
87 }
88}
89
90export class Transport {
91 #child?: ChildProcessWithoutNullStreams;
92 #stdin?: Writable;
93 #pending = new Map<bigint, UnaryPending | StreamPending>();
94 #nextId = 1n;
95 #closed = false;
96 #starting?: Promise<void>;
97
98 constructor(
99 private readonly config: ClientConfig,
100 private readonly binaryPath: string,
101 ) {}
102
103 /** @internal test seam */
104 attachStreamsForTest(stdin: Writable, stdout: Readable): void {
105 this.#stdin = stdin;
106 this.#child = { stdin } as unknown as ChildProcessWithoutNullStreams;
107 this.#startReader(stdout);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected