Skip to content

Commit c7919fa

Browse files
committed
fix(runner): remove top level await (#2848)
1 parent e3ba990 commit c7919fa

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"packageManager": "pnpm@10.13.1",
55
"scripts": {
66
"start": "npx turbo watch build",
7+
"build": "npx turbo build",
78
"test": "npx turbo test",
89
"test:watch": "npx turbo watch test",
910
"check-types": "npx turbo check-types",

sdks/typescript/runner/src/mod.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { unreachable, calculateBackoff } from "./utils.js";
55
import { Tunnel } from "./tunnel.js";
66
import { WebSocketTunnelAdapter } from "./websocket-tunnel-adapter.js";
77

8-
const WS = await importWebSocket();
9-
108
const KV_EXPIRE: number = 30_000;
119

1210
interface 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

Comments
 (0)