Skip to content

Simplify asyncLoad. NFC #23100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2181,18 +2181,14 @@ addToLibrary({
return x.startsWith('dynCall_') ? x : '_' + x;
},

$asyncLoad__docs: '/** @param {boolean=} noRunDep */',
$asyncLoad: (url, noRunDep) => {
$asyncLoad: (url) => {
return new Promise((resolve, reject) => {
var dep = !noRunDep ? getUniqueRunDependency(`al ${url}`) : '';
if (dep) addRunDependency(dep);
readAsync(url).then(
(arrayBuffer) => {
#if ASSERTIONS
assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
#endif
resolve(new Uint8Array(arrayBuffer));
if (dep) removeRunDependency(dep);
}, reject);
});
},
Expand Down
2 changes: 1 addition & 1 deletion src/library_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ addToLibrary({
emscripten_wget_data: (url, pbuffer, pnum, perror) => {
return Asyncify.handleSleep((wakeUp) => {
/* no need for run dependency, this is async but will not do any prepare etc. step */
asyncLoad(UTF8ToString(url), /*noRunDep=*/true).then((byteArray) => {
asyncLoad(UTF8ToString(url)).then((byteArray) => {
// can only allocate the buffer after the wakeUp, not during an asyncing
var buffer = _malloc(byteArray.length); // must be freed by caller!
HEAPU8.set(byteArray, buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/library_wget.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var LibraryWget = {
emscripten_async_wget_data: (url, userdata, onload, onerror) => {
{{{ runtimeKeepalivePush() }}}
/* no need for run dependency, this is async but will not do any prepare etc. step */
asyncLoad(UTF8ToString(url), /*noRunDep=*/true).then((byteArray) => {
asyncLoad(UTF8ToString(url)).then((byteArray) => {
{{{ runtimeKeepalivePop() }}}
callUserCallback(() => {
var buffer = _malloc(byteArray.length);
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 @@
6294
6276
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 @@
13863
13831
Loading