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

Method #spawn

node/src/transport.ts:144–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142 #startReader(stdout: Readable): void {
143 void (async () => {
144 try {
145 for await (const envelope of sizeDelimitedDecodeStream(EnvelopeSchema, stdout)) {
146 this.#dispatch(envelope);
147 }
148 this.#failAll(new ConnectionError("cmdop-core stdout closed", "transport"));
149 } catch (error) {
150 this.#failAll(
151 new ConnectionError(
152 `core read failed: ${error instanceof Error ? error.message : String(error)}`,
153 "transport",
154 ),
155 );
156 }
157 })();
158 }
159
160 #dispatch(envelope: Envelope): void {
161 const pending = this.#pending.get(envelope.id);
162 if (!pending) return;
163 if (pending.kind === "unary") {
164 if (envelope.kind === Envelope_Kind.RESPONSE) {
165 this.#pending.delete(envelope.id);
166 clearTimeout(pending.timer);
167 pending.resolve(envelope);
168 } else if (envelope.kind === Envelope_Kind.ERROR && envelope.payload.case === "error") {
169 this.#pending.delete(envelope.id);
170 clearTimeout(pending.timer);
171 pending.reject(mapCoreError(envelope.payload.value));
172 }
173 return;
174 }
175 if (envelope.kind === Envelope_Kind.EVENT) {

Callers 1

ensureStartedMethod · 0.95

Calls 2

#failAllMethod · 0.95
#startReaderMethod · 0.95

Tested by

no test coverage detected