GeezerVison is showing github.com — Apply PR #15013: refactor: replace Bun.sleep with node timers · anomalyco/opencode@c88f35a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: github/index.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,6 +8,7 @@ import type { Context as GitHubContext } from "@actions/github/lib/context" | 8 | 8 | import type { IssueCommentEvent, PullRequestReviewCommentEvent } from "@octokit/webhooks-types" | 9 | 9 | import { createOpencodeClient } from "@opencode-ai/sdk" | 10 | 10 | import { spawn } from "node:child_process" | | 11 | +import { setTimeout as sleep } from "node:timers/promises" | 11 | 12 |
| 12 | 13 | type GitHubAuthor = { | 13 | 14 | login: string | @@ -281,7 +282,7 @@ async function assertOpencodeConnected() { | 281 | 282 | connected = true | 282 | 283 | break | 283 | 284 | } catch (e) {} | 284 | | - await Bun.sleep(300) | | 285 | + await sleep(300) | 285 | 286 | } while (retry++ < 30) | 286 | 287 |
| 287 | 288 | if (!connected) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/auth.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ import { Instance } from "../../project/instance" | 13 | 13 | import type { Hooks } from "@opencode-ai/plugin" | 14 | 14 | import { Process } from "../../util/process" | 15 | 15 | import { text } from "node:stream/consumers" | | 16 | +import { setTimeout as sleep } from "node:timers/promises" | 16 | 17 |
| 17 | 18 | type PluginAuth = NonNullable<Hooks["auth"]> | 18 | 19 |
| @@ -38,7 +39,7 @@ async function handlePluginAuth(plugin: { auth: PluginAuth }, provider: string): | 38 | 39 | const method = plugin.auth.methods[index] | 39 | 40 |
| 40 | 41 | // Handle prompts for all auth types | 41 | | - await Bun.sleep(10) | | 42 | + await sleep(10) | 42 | 43 | const inputs: Record<string, string> = {} | 43 | 44 | if (method.prompts) { | 44 | 45 | for (const prompt of method.prompts) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/debug/lsp.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { bootstrap } from "../../bootstrap" | 3 | 3 | import { cmd } from "../cmd" | 4 | 4 | import { Log } from "../../../util/log" | 5 | 5 | import { EOL } from "os" | | 6 | +import { setTimeout as sleep } from "node:timers/promises" | 6 | 7 |
| 7 | 8 | export const LSPCommand = cmd({ | 8 | 9 | command: "lsp", | @@ -19,7 +20,7 @@ const DiagnosticsCommand = cmd({ | 19 | 20 | async handler(args) { | 20 | 21 | await bootstrap(process.cwd(), async () => { | 21 | 22 | await LSP.touchFile(args.file, true) | 22 | | - await Bun.sleep(1000) | | 23 | + await sleep(1000) | 23 | 24 | process.stdout.write(JSON.stringify(await LSP.diagnostics(), null, 2) + EOL) | 24 | 25 | }) | 25 | 26 | }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/github.ts +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,6 +28,7 @@ import { Bus } from "../../bus" | 28 | 28 | import { MessageV2 } from "../../session/message-v2" | 29 | 29 | import { SessionPrompt } from "@/session/prompt" | 30 | 30 | import { $ } from "bun" | | 31 | +import { setTimeout as sleep } from "node:timers/promises" | 31 | 32 |
| 32 | 33 | type GitHubAuthor = { | 33 | 34 | login: string | @@ -353,7 +354,7 @@ export const GithubInstallCommand = cmd({ | 353 | 354 | } | 354 | 355 |
| 355 | 356 | retries++ | 356 | | - await Bun.sleep(1000) | | 357 | + await sleep(1000) | 357 | 358 | } while (true) | 358 | 359 |
| 359 | 360 | s.stop("Installed GitHub app") | @@ -1372,7 +1373,7 @@ Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"` | 1372 | 1373 | } catch (e) { | 1373 | 1374 | if (retries > 0) { | 1374 | 1375 | console.log(`Retrying after ${delayMs}ms...`) | 1375 | | - await Bun.sleep(delayMs) | | 1376 | + await sleep(delayMs) | 1376 | 1377 | return withRetry(fn, retries - 1, delayMs) | 1377 | 1378 | } | 1378 | 1379 | throw e | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/worker.ts +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ import { GlobalBus } from "@/bus/global" | 10 | 10 | import { createOpencodeClient, type Event } from "@opencode-ai/sdk/v2" | 11 | 11 | import type { BunWebSocketData } from "hono/bun" | 12 | 12 | import { Flag } from "@/flag/flag" | | 13 | +import { setTimeout as sleep } from "node:timers/promises" | 13 | 14 |
| 14 | 15 | await Log.init({ | 15 | 16 | print: process.argv.includes("--print-logs"), | @@ -75,7 +76,7 @@ const startEventStream = (directory: string) => { | 75 | 76 | ).catch(() => undefined) | 76 | 77 |
| 77 | 78 | if (!events) { | 78 | | - await Bun.sleep(250) | | 79 | + await sleep(250) | 79 | 80 | continue | 80 | 81 | } | 81 | 82 |
| @@ -84,7 +85,7 @@ const startEventStream = (directory: string) => { | 84 | 85 | } | 85 | 86 |
| 86 | 87 | if (!signal.aborted) { | 87 | | - await Bun.sleep(250) | | 88 | + await sleep(250) | 88 | 89 | } | 89 | 90 | } | 90 | 91 | })().catch((error) => { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/plugin/codex.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ import { Installation } from "../installation" | 4 | 4 | import { Auth, OAUTH_DUMMY_KEY } from "../auth" | 5 | 5 | import os from "os" | 6 | 6 | import { ProviderTransform } from "@/provider/transform" | | 7 | +import { setTimeout as sleep } from "node:timers/promises" | 7 | 8 |
| 8 | 9 | const log = Log.create({ service: "plugin.codex" }) | 9 | 10 |
| @@ -602,7 +603,7 @@ export async function CodexAuthPlugin(input: PluginInput): Promise<Hooks> { | 602 | 603 | return { type: "failed" as const } | 603 | 604 | } | 604 | 605 |
| 605 | | - await Bun.sleep(interval + OAUTH_POLLING_SAFETY_MARGIN_MS) | | 606 | + await sleep(interval + OAUTH_POLLING_SAFETY_MARGIN_MS) | 606 | 607 | } | 607 | 608 | }, | 608 | 609 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/plugin/copilot.ts +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import type { Hooks, PluginInput } from "@opencode-ai/plugin" | 2 | 2 | import { Installation } from "@/installation" | 3 | 3 | import { iife } from "@/util/iife" | | 4 | +import { setTimeout as sleep } from "node:timers/promises" | 4 | 5 |
| 5 | 6 | const CLIENT_ID = "Ov23li8tweQw6odWQebz" | 6 | 7 | // Add a small safety buffer when polling to avoid hitting the server | @@ -270,7 +271,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> { | 270 | 271 | } | 271 | 272 |
| 272 | 273 | if (data.error === "authorization_pending") { | 273 | | - await Bun.sleep(deviceData.interval * 1000 + OAUTH_POLLING_SAFETY_MARGIN_MS) | | 274 | + await sleep(deviceData.interval * 1000 + OAUTH_POLLING_SAFETY_MARGIN_MS) | 274 | 275 | continue | 275 | 276 | } | 276 | 277 |
| @@ -286,13 +287,13 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> { | 286 | 287 | newInterval = serverInterval * 1000 | 287 | 288 | } | 288 | 289 |
| 289 | | - await Bun.sleep(newInterval + OAUTH_POLLING_SAFETY_MARGIN_MS) | | 290 | + await sleep(newInterval + OAUTH_POLLING_SAFETY_MARGIN_MS) | 290 | 291 | continue | 291 | 292 | } | 292 | 293 |
| 293 | 294 | if (data.error) return { type: "failed" as const } | 294 | 295 |
| 295 | | - await Bun.sleep(deviceData.interval * 1000 + OAUTH_POLLING_SAFETY_MARGIN_MS) | | 296 | + await sleep(deviceData.interval * 1000 + OAUTH_POLLING_SAFETY_MARGIN_MS) | 296 | 297 | continue | 297 | 298 | } | 298 | 299 | }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/shell/shell.ts +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ import { Filesystem } from "@/util/filesystem" | 4 | 4 | import { which } from "@/util/which" | 5 | 5 | import path from "path" | 6 | 6 | import { spawn, type ChildProcess } from "child_process" | | 7 | +import { setTimeout as sleep } from "node:timers/promises" | 7 | 8 |
| 8 | 9 | const SIGKILL_TIMEOUT_MS = 200 | 9 | 10 |
| @@ -23,13 +24,13 @@ export namespace Shell { | 23 | 24 |
| 24 | 25 | try { | 25 | 26 | process.kill(-pid, "SIGTERM") | 26 | | - await Bun.sleep(SIGKILL_TIMEOUT_MS) | | 27 | + await sleep(SIGKILL_TIMEOUT_MS) | 27 | 28 | if (!opts?.exited?.()) { | 28 | 29 | process.kill(-pid, "SIGKILL") | 29 | 30 | } | 30 | 31 | } catch (_e) { | 31 | 32 | proc.kill("SIGTERM") | 32 | | - await Bun.sleep(SIGKILL_TIMEOUT_MS) | | 33 | + await sleep(SIGKILL_TIMEOUT_MS) | 33 | 34 | if (!opts?.exited?.()) { | 34 | 35 | proc.kill("SIGKILL") | 35 | 36 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/test/preload.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | import os from "os" | 4 | 4 | import path from "path" | 5 | 5 | import fs from "fs/promises" | | 6 | +import { setTimeout as sleep } from "node:timers/promises" | 6 | 7 | import { afterAll } from "bun:test" | 7 | 8 |
| 8 | 9 | // Set XDG env vars FIRST, before any src/ imports | @@ -15,7 +16,7 @@ afterAll(async () => { | 15 | 16 | typeof error === "object" && error !== null && "code" in error && error.code === "EBUSY" | 16 | 17 | const rm = async (left: number): Promise<void> => { | 17 | 18 | Bun.gc(true) | 18 | | - await Bun.sleep(100) | | 19 | + await sleep(100) | 19 | 20 | return fs.rm(dir, { recursive: true, force: true }).catch((error) => { | 20 | 21 | if (!busy(error)) throw error | 21 | 22 | if (left <= 1) throw error | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/test/pty/pty-output-isolation.test.ts +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test" | 2 | 2 | import { Instance } from "../../src/project/instance" | 3 | 3 | import { Pty } from "../../src/pty" | 4 | 4 | import { tmpdir } from "../fixture/fixture" | | 5 | +import { setTimeout as sleep } from "node:timers/promises" | 5 | 6 |
| 6 | 7 | describe("pty", () => { | 7 | 8 | test("does not leak output when websocket objects are reused", async () => { | @@ -43,7 +44,7 @@ describe("pty", () => { | 43 | 44 |
| 44 | 45 | // Output from a must never show up in b. | 45 | 46 | Pty.write(a.id, "AAA\n") | 46 | | - await Bun.sleep(100) | | 47 | + await sleep(100) | 47 | 48 |
| 48 | 49 | expect(outB.join("")).not.toContain("AAA") | 49 | 50 | } finally { | @@ -88,7 +89,7 @@ describe("pty", () => { | 88 | 89 | } | 89 | 90 |
| 90 | 91 | Pty.write(a.id, "AAA\n") | 91 | | - await Bun.sleep(100) | | 92 | + await sleep(100) | 92 | 93 |
| 93 | 94 | expect(outB.join("")).not.toContain("AAA") | 94 | 95 | } finally { | @@ -128,7 +129,7 @@ describe("pty", () => { | 128 | 129 | ctx.connId = 2 | 129 | 130 |
| 130 | 131 | Pty.write(a.id, "AAA\n") | 131 | | - await Bun.sleep(100) | | 132 | + await sleep(100) | 132 | 133 |
| 133 | 134 | expect(out.join("")).toContain("AAA") | 134 | 135 | } finally { | |
|