Skip to content

Commit b50462d

Browse files
Copilothotlong
andcommitted
Replace Atomics.wait with sleepSync for Node.js compatibility
- Replace Atomics.wait (which doesn't work on main thread) with a simple busy-wait sleepSync - Add sleepSync utility for synchronous delays in build scripts - This ensures the retry logic works correctly in all environments Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent d47403c commit b50462d

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

packages/spec/scripts/build-schemas.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import * as Protocol from '../src/index';
66

77
const OUT_DIR = path.resolve(__dirname, '../json-schema');
88

9+
/**
10+
* Synchronous sleep utility using a busy-wait loop
11+
* Only use for short delays in build scripts where blocking is acceptable
12+
*/
13+
function sleepSync(ms: number): void {
14+
const end = Date.now() + ms;
15+
while (Date.now() < end) {
16+
// Busy wait
17+
}
18+
}
19+
920
/**
1021
* Safely ensure directory exists with retry logic
1122
*/
@@ -25,7 +36,7 @@ function ensureDir(dirPath: string, retries = 3): void {
2536
}
2637
// Wait a bit before retrying
2738
const delay = 100 * (i + 1);
28-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delay);
39+
sleepSync(delay);
2940
}
3041
}
3142
}
@@ -48,7 +59,7 @@ function writeFileWithRetry(filePath: string, content: string, retries = 3): voi
4859
}
4960
// Wait a bit before retrying
5061
const delay = 100 * (i + 1);
51-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delay);
62+
sleepSync(delay);
5263
}
5364
}
5465
}
@@ -60,8 +71,7 @@ if (fs.existsSync(OUT_DIR)) {
6071

6172
// Wait a bit to ensure file system has synced
6273
// This prevents ENOENT errors on some file systems
63-
const syncDelay = 50;
64-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, syncDelay);
74+
sleepSync(50);
6575
}
6676

6777
// Ensure output directory exists

0 commit comments

Comments
 (0)