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

Method ready

packages/computer/src/workspace.ts:493–525  ·  view source on GitHub ↗
(options?: string | { all?: boolean })

Source from the content-addressed store, hash-verified

491 // `{ all: true }` to dial every backend in parallel — useful
492 // from an agent's `onStart` hook.
493 ready(options?: string | { all?: boolean }): Promise<void> {
494 if (this.#readyPromise === undefined) {
495 const pass = this.#mountIndex.ensureIndexed();
496 this.#readyPromise = pass;
497 pass.catch(() => {
498 // A failed mount-index pass must not poison this
499 // Workspace forever. The next ready() should re-enter
500 // ensureIndexed() and try again.
501 if (this.#readyPromise === pass) this.#readyPromise = undefined;
502 });
503 }
504 const indexPromise = this.#readyPromise;
505 if (options === undefined) return indexPromise;
506 if (typeof options === "string") {
507 const id = this.#resolveBackendId(options);
508 return (async () => {
509 await indexPromise;
510 if (!id) return;
511 if (this.#moduleBackendsById.has(id)) await this.#moduleHandleFor(id);
512 else await this.#handleFor(id);
513 })();
514 }
515 if (options.all) {
516 return (async () => {
517 await indexPromise;
518 await Promise.all([
519 ...this.#backends.map((backend) => this.#handleFor(backend.id)),
520 ...[...this.#moduleBackendsById.keys()].map((id) => this.#moduleHandleFor(id)),
521 ]);
522 })();
523 }
524 return indexPromise;
525 }
526
527 // Wrap this workspace in a WorkspaceStub so it can be handed
528 // across the Workers-RPC boundary (e.g. returned from a DO RPC

Callers 1

withStubFunction · 0.95

Calls 6

#resolveBackendIdMethod · 0.95
#moduleHandleForMethod · 0.95
#handleForMethod · 0.95
ensureIndexedMethod · 0.80
hasMethod · 0.80
allMethod · 0.80

Tested by 1

withStubFunction · 0.76