Skip to content

Commit a764fdb

Browse files
authored
Merge pull request #1996 from o1-labs/fix/snarky-undefined
Make sure bindings are initialized before accessing snarky
2 parents c5bbf8b + 20e0352 commit a764fdb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2525
- Sort order for actions now includes the transaction sequence number and the exact account id sequence https://github.com/o1-labs/o1js/pull/1917
2626
- Updated typedoc version for generating docs https://github.com/o1-labs/o1js/pull/1973
2727

28+
### Fixed
29+
30+
- Fix behavior of `initializeBindings()` when called concurrently, to improve error messages in common failure scenarios https://github.com/o1-labs/o1js/pull/1996
31+
2832
## [2.2.0](https://github.com/o1-labs/o1js/compare/e1bac02...b857516) - 2024-12-10
2933

3034
### Added

src/snarky.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import { wasm, withThreadPool } from './bindings/js/node/node-backend.js';
33

44
let Snarky, Ledger, Pickles, Test_;
55
let isInitialized = false;
6+
let initializingPromise;
67

78
async function initializeBindings() {
89
if (isInitialized) return;
9-
isInitialized = true;
10+
if (initializingPromise) {
11+
await initializingPromise;
12+
return;
13+
}
1014
let snarky;
15+
let resolve;
16+
initializingPromise = new Promise((r) => (resolve = r));
1117

1218
// this dynamic import makes jest respect the import order
1319
// otherwise the cjs file gets imported before its implicit esm dependencies and fails
@@ -18,6 +24,9 @@ async function initializeBindings() {
1824
await import('./bindings/compiled/_node_bindings/o1js_node.bc.cjs')
1925
).default;
2026
({ Snarky, Ledger, Pickles, Test: Test_ } = snarky);
27+
resolve();
28+
initializingPromise = undefined;
29+
isInitialized = true;
2130
}
2231

2332
async function Test() {

0 commit comments

Comments
 (0)