Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-waves-98e80b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vercel/sandbox": patch
---

Add `wait` option to `getCommand` to allow fetching command state without waiting for completion
21 changes: 13 additions & 8 deletions packages/vercel-sandbox/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import { WithFetchOptions } from "./api-client/api-client";
import { RUNTIMES } from "./constants";
import { Snapshot } from "./snapshot";
import { consumeReadable } from "./utils/consume-readable";
import {
toAPINetworkPolicy,
type NetworkPolicy,
} from "./utils/network-policy";
import { toAPINetworkPolicy, type NetworkPolicy } from "./utils/network-policy";

export type { NetworkPolicy };

Expand Down Expand Up @@ -323,15 +320,23 @@ export class Sandbox {
* @param cmdId - ID of the command to retrieve
* @param opts - Optional parameters.
* @param opts.signal - An AbortSignal to cancel the operation.
* @param opts.wait - If false, will not wait for the command to complete.
* @returns A {@link Command} instance representing the command
*/
async getCommand(
cmdId: string,
opts?: { signal?: AbortSignal },
opts?: {
signal?: AbortSignal;
/**
* If false, will not wait for the command to complete.
*/
wait?: boolean;
},
): Promise<Command> {
const command = await this.client.getCommand({
sandboxId: this.sandbox.id,
cmdId,
wait: opts?.wait,
signal: opts?.signal,
});

Expand Down Expand Up @@ -413,7 +418,7 @@ export class Sandbox {
}
})();
}
}
};

if (wait) {
const commandStream = await this.client.runCommand({
Expand All @@ -433,7 +438,7 @@ export class Sandbox {
cmd: commandStream.command,
});

getLogs(command);
getLogs(command);

const finished = await commandStream.finished;
return new CommandFinished({
Expand Down Expand Up @@ -562,7 +567,7 @@ export class Sandbox {
});
return dstPath;
} finally {
stream.destroy()
stream.destroy();
}
}

Expand Down