Skip to content

Commit

Permalink
Initial usage of async/await in JS library code. NFC (#23104)
Browse files Browse the repository at this point in the history
Convert asyncLoad from promises to async/await.

This lays the groundwork for more a larger usage in #23068
  • Loading branch information
sbc100 authored Dec 9, 2024
1 parent d1ea4c3 commit f1c321a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2181,16 +2181,12 @@ addToLibrary({
return x.startsWith('dynCall_') ? x : '_' + x;
},

$asyncLoad: (url) => {
return new Promise((resolve, reject) => {
readAsync(url).then(
(arrayBuffer) => {
$asyncLoad: async (url) => {
var arrayBuffer = await readAsync(url);
#if ASSERTIONS
assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
#endif
resolve(new Uint8Array(arrayBuffer));
}, reject);
});
return new Uint8Array(arrayBuffer);
},

$alignMemory: (size, alignment) => {
Expand Down
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_dylink.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6276
6274
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_dylink.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13831
13816

0 comments on commit f1c321a

Please sign in to comment.