@@ -5,8 +5,6 @@ import { unreachable, calculateBackoff } from "./utils.js";
55import { Tunnel } from "./tunnel.js" ;
66import { WebSocketTunnelAdapter } from "./websocket-tunnel-adapter.js" ;
77
8- const WS = await importWebSocket ( ) ;
9-
108const KV_EXPIRE : number = 30_000 ;
119
1210interface ActorInstance {
@@ -215,12 +213,12 @@ export class Runner {
215213 }
216214
217215 // MARK: Start
218- start ( ) {
216+ async start ( ) {
219217 if ( this . #started) throw new Error ( "Cannot call runner.start twice" ) ;
220218 this . #started = true ;
221219
222220 console . log ( "[RUNNER] Starting runner" ) ;
223- this . #openPegboardWebSocket( ) ;
221+ await this . #openPegboardWebSocket( ) ;
224222 this . #openTunnel( ) ;
225223
226224 process . on ( "SIGTERM" , this . shutdown . bind ( this , false , true ) ) ;
@@ -378,7 +376,8 @@ export class Runner {
378376 }
379377
380378 // MARK: Runner protocol
381- #openPegboardWebSocket( ) {
379+ async #openPegboardWebSocket( ) {
380+ const WS = await importWebSocket ( ) ;
382381 const ws = new WS ( this . pegboardUrl , {
383382 headers : {
384383 "x-rivet-target" : "runner-ws" ,
@@ -1177,13 +1176,13 @@ export class Runner {
11771176 `Scheduling reconnect attempt ${ this . #reconnectAttempt + 1 } in ${ delay } ms` ,
11781177 ) ;
11791178
1180- this . #reconnectTimeout = setTimeout ( ( ) => {
1179+ this . #reconnectTimeout = setTimeout ( async ( ) => {
11811180 if ( ! this . #shutdown) {
11821181 this . #reconnectAttempt++ ;
11831182 console . log (
11841183 `Attempting to reconnect (attempt ${ this . #reconnectAttempt} )...` ,
11851184 ) ;
1186- this . #openPegboardWebSocket( ) ;
1185+ await this . #openPegboardWebSocket( ) ;
11871186 }
11881187 } , delay ) ;
11891188 }
0 commit comments