-
Notifications
You must be signed in to change notification settings - Fork 2.7k
refactor(cli): replace spawnSync("sleep") with native wait utility #2027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brandonpelfrey
merged 16 commits into
NVIDIA:main
from
ksapru:refactor/native-sleep-utility
Apr 21, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fc2276f
refactor(cli): replace spawnSync("sleep") with native wait utility
ksapru d38e1dd
fix(cli): address review feedback for native wait utility
ksapru 52d57a5
Merge branch 'main' into refactor/native-sleep-utility
ksapru 0f5c710
Merge branch 'main' into refactor/native-sleep-utility
ksapru b3737e7
test(wait): use performance.now() for monotonic timing stabilization
ksapru 66caaf1
Merge branch 'main' into refactor/native-sleep-utility
ksapru 83d189d
Merge branch 'main' into refactor/native-sleep-utility
ksapru f7d55c5
Merge branch 'main' into refactor/native-sleep-utility
ksapru 7f4b074
Merge branch 'main' into refactor/native-sleep-utility
ksapru 170dcbc
Merge branch 'main' into refactor/native-sleep-utility
ksapru 4b8924f
Merge branch 'main' into refactor/native-sleep-utility
ksapru 4aeed39
fix(cli): resolve import extension and stale eslint comments from review
ksapru 6661d93
Merge branch 'main' into refactor/native-sleep-utility
ksapru 709b0b8
Merge branch 'main' into refactor/native-sleep-utility
ksapru d627c69
Merge branch 'main' into refactor/native-sleep-utility
ksapru 0448ed5
Merge branch 'main' into refactor/native-sleep-utility
ksapru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** | ||
| * Synchronous waiting primitives for CLI commands. | ||
| */ | ||
|
|
||
| /** | ||
| * Synchronously sleep for the given number of milliseconds. | ||
| * Uses Atomics.wait to block without pegging the CPU. | ||
| */ | ||
| export function sleepMs(ms: number): void { | ||
| if (ms <= 0 || !Number.isFinite(ms)) return; | ||
| const buffer = new Int32Array(new SharedArrayBuffer(4)); | ||
| Atomics.wait(buffer, 0, 0, ms); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Synchronously sleep for the given number of seconds. | ||
| */ | ||
| export function sleepSeconds(seconds: number): void { | ||
| sleepMs(seconds * 1000); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import assert from "node:assert"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { sleepMs, sleepSeconds } from "../src/lib/wait.js"; | ||
|
|
||
| describe("wait utility", () => { | ||
| it("sleepMs blocks for approximately the requested time", () => { | ||
| const start = performance.now(); | ||
| sleepMs(100); | ||
| const end = performance.now(); | ||
| const duration = end - start; | ||
|
|
||
| // Allow for some jitter, but should be at least 100ms. | ||
| // Increased upper bound to 500ms to avoid CI flakes on loaded runners. | ||
| assert.ok(duration >= 100, `duration ${duration}ms < 100ms`); | ||
| assert.ok(duration < 500, `duration ${duration}ms > 500ms`); | ||
| }); | ||
|
|
||
| it("sleepSeconds blocks for approximately the requested time", () => { | ||
| const start = performance.now(); | ||
| sleepSeconds(0.1); | ||
| const end = performance.now(); | ||
| const duration = end - start; | ||
|
|
||
| assert.ok(duration >= 100, `duration ${duration}ms < 100ms`); | ||
| assert.ok(duration < 500, `duration ${duration}ms > 500ms`); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| it("returns immediately for zero, negative, or non-finite time", () => { | ||
| const start = performance.now(); | ||
| sleepMs(0); | ||
| sleepMs(-50); | ||
| sleepMs(NaN); | ||
| sleepMs(Infinity); | ||
| const end = performance.now(); | ||
| const duration = end - start; | ||
| assert.ok(duration < 50, `duration ${duration}ms > 50ms`); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.