File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments