Skip to content

Commit 07a8870

Browse files
sbc100hedwigz
authored andcommitted
Initial usage of async/await in JS library code. NFC (emscripten-core#23104)
Convert asyncLoad from promises to async/await. This lays the groundwork for more a larger usage in emscripten-core#23068
1 parent 188eff5 commit 07a8870

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

src/library.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -2194,16 +2194,12 @@ addToLibrary({
21942194
return x.startsWith('dynCall_') ? x : '_' + x;
21952195
},
21962196

2197-
$asyncLoad: (url) => {
2198-
return new Promise((resolve, reject) => {
2199-
readAsync(url).then(
2200-
(arrayBuffer) => {
2197+
$asyncLoad: async (url) => {
2198+
var arrayBuffer = await readAsync(url);
22012199
#if ASSERTIONS
2202-
assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
2200+
assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
22032201
#endif
2204-
resolve(new Uint8Array(arrayBuffer));
2205-
}, reject);
2206-
});
2202+
return new Uint8Array(arrayBuffer);
22072203
},
22082204

22092205
$alignMemory: (size, alignment) => {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6276
1+
6274
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13831
1+
13816

0 commit comments

Comments
 (0)