Skip to content

Commit 0af1c19

Browse files
committed
refactor(preflight): use node:timers/promises sleep instead of custom delay
Replace custom delay function with built-in setTimeout from node:timers/promises (aliased as sleep) for better maintainability and consistency with Node.js best practices.
1 parent 423fdb2 commit 0af1c19

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

packages/cli/src/utils/preflight/downloads.mts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010
* This runs asynchronously and never blocks the main CLI execution.
1111
*/
1212

13+
import { setTimeout as sleep } from 'node:timers/promises'
14+
1315
import { downloadPackage } from '@socketsecurity/lib/dlx-package'
1416

1517
import ENV from '../../constants/env.mts'
1618
import { ensurePython, ensureSocketPythonCli } from '../python/standalone.mts'
1719

18-
/**
19-
* Delay execution for a specified number of milliseconds.
20-
*/
21-
function delay(ms: number): Promise<void> {
22-
return new Promise((resolve) => setTimeout(resolve, ms))
23-
}
24-
2520
/**
2621
* Track if preflight downloads have already been initiated.
2722
*/
@@ -60,7 +55,7 @@ export function runPreflightDownloads(): void {
6055
})
6156

6257
// Delay before next download (1-3 seconds).
63-
await delay(1000 + Math.random() * 2000)
58+
await sleep(1000 + Math.random() * 2000)
6459

6560
// 2. @cyclonedx/cdxgen preflight.
6661
const cdxgenVersion = ENV.INLINED_SOCKET_CLI_CYCLONEDX_CDXGEN_VERSION
@@ -72,7 +67,7 @@ export function runPreflightDownloads(): void {
7267
})
7368

7469
// Delay before next download (1-3 seconds).
75-
await delay(1000 + Math.random() * 2000)
70+
await sleep(1000 + Math.random() * 2000)
7671

7772
// 3. Python + socketsecurity (socket-python-cli) preflight.
7873
const pythonBin = await ensurePython()

0 commit comments

Comments
 (0)