MCPcopy Create free account
hub / github.com/cloudflare/computer / WorkspaceRuntimeExecHandleStub

Class WorkspaceRuntimeExecHandleStub

packages/computer/src/stub.ts:280–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278}
279
280export class WorkspaceRuntimeExecHandleStub<
281 E extends "utf8" | undefined = undefined,
282> extends RpcTarget {
283 readonly #handle: WorkspaceRuntimeExecHandle<E>;
284 #consumed = false;
285 #disposed = false;
286 #reader: ReadableStreamDefaultReader<WorkspaceRuntimeEvent<"utf8" | undefined>> | undefined;
287
288 constructor(handle: WorkspaceRuntimeExecHandle<E>) {
289 super();
290 this.#handle = handle;
291 trackStub(this);
292 }
293
294 [Symbol.dispose](): void {
295 if (this.#disposed) return;
296 this.#disposed = true;
297 const reader = this.#reader;
298 this.#reader = undefined;
299 if (reader) {
300 void reader
301 .cancel()
302 .catch(() => undefined)
303 .finally(() => reader.releaseLock());
304 } else {
305 const cancel = (this.#handle as { cancel?: () => Promise<void> }).cancel;
306 if (typeof cancel === "function") void cancel.call(this.#handle).catch(() => undefined);
307 }
308 untrackStub(this);
309 }
310
311 get id(): string {
312 return this.#handle.id;
313 }
314
315 get backend(): string {
316 return this.#handle.backend;
317 }
318
319 async result(): Promise<WorkspaceRuntimeResult<E>> {
320 this.#claim();
321 return this.#handle.result();
322 }
323
324 stream(): ReadableStream<Uint8Array> {
325 this.#claim();
326 const reader = (
327 this.#handle as ReadableStream<WorkspaceRuntimeEvent<"utf8" | undefined>>
328 ).getReader();
329 this.#reader = reader;
330 const owner = this;
331 return new ReadableStream<Uint8Array>(
332 {
333 async pull(controller) {
334 try {
335 const { value, done } = await reader.read();
336 if (done) {
337 reader.releaseLock();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected