Skip to content

Commit 7ad63d7

Browse files
authored
feat: allow sandbox to keep active while connected (#53)
1 parent 7bf1e35 commit 7ad63d7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/sandbox.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,28 @@ export class Sandbox extends SandboxSession {
260260
public async updateHibernationTimeout(timeoutSeconds: number): Promise<void> {
261261
await this.sandboxClient.updateHibernationTimeout(this.id, timeoutSeconds);
262262
}
263+
264+
private keepAliveInterval: NodeJS.Timeout | null = null;
265+
/**
266+
* If enabled, we will keep the sandbox from hibernating as long as the SDK is connected to it.
267+
*/
268+
public keepActiveWhileConnected(enabled: boolean) {
269+
if (enabled && !this.keepAliveInterval) {
270+
this.keepAliveInterval = setInterval(() => {
271+
this.pitcherClient.clients.system.update();
272+
}, 1000 * 30);
273+
274+
this.onWillDispose(() => {
275+
if (this.keepAliveInterval) {
276+
clearInterval(this.keepAliveInterval);
277+
this.keepAliveInterval = null;
278+
}
279+
});
280+
} else {
281+
if (this.keepAliveInterval) {
282+
clearInterval(this.keepAliveInterval);
283+
this.keepAliveInterval = null;
284+
}
285+
}
286+
}
263287
}

0 commit comments

Comments
 (0)