Skip to content

Commit 3b81189

Browse files
authored
[ASYNCIFY] Convert remaining async JS function to use auto (#26117)
The only function that remains that still uses `async: true` is `emscripten_fiber_swap`, and this is because it doesn't use handleSleep or handleAsync, so is not a candidate for `async: auto`. Followup to #26019 and #26095.
1 parent bed4a48 commit 3b81189

3 files changed

Lines changed: 10 additions & 14 deletions

File tree

src/lib/libasync.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ addToLibrary({
446446
//
447447
// This is particularly useful for native JS `async` functions where the
448448
// returned value will "just work" and be passed back to C++.
449-
handleAsync: (startAsync) => Asyncify.handleSleep((wakeUp) => {
449+
handleAsync: (startAsync) => Asyncify.handleSleep(async (wakeUp) => {
450450
// TODO: add error handling as a second param when handleSleep implements it.
451-
startAsync().then(wakeUp);
451+
wakeUp(await startAsync());
452452
}),
453453

454454
#elif ASYNCIFY == 2
@@ -480,8 +480,8 @@ addToLibrary({
480480
#endif
481481
},
482482

483-
emscripten_sleep__async: true,
484-
emscripten_sleep: (ms) => Asyncify.handleSleep((wakeUp) => setTimeout(wakeUp, ms)),
483+
emscripten_sleep__async: 'auto',
484+
emscripten_sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
485485

486486
emscripten_wget_data__deps: ['$asyncLoad', 'malloc'],
487487
emscripten_wget_data__async: 'auto',
@@ -518,7 +518,7 @@ addToLibrary({
518518
},
519519

520520
_load_secondary_module__sig: 'v',
521-
_load_secondary_module__async: true,
521+
_load_secondary_module__async: 'auto',
522522
_load_secondary_module: async function() {
523523
// Mark the module as loading for the wasm module (so it doesn't try to load it again).
524524
wasmExports['load_secondary_module_status'].value = 1;

src/lib/libwasi.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,16 @@ var WasiLibrary = {
540540
return 0;
541541
},
542542

543-
fd_sync__async: true,
543+
fd_sync__async: 'auto',
544544
fd_sync: (fd) => {
545545
#if SYSCALLS_REQUIRE_FILESYSTEM
546546
var stream = SYSCALLS.getStreamFromFD(fd);
547547
var rtn = stream.stream_ops?.fsync?.(stream);
548548
#if ASYNCIFY
549549
var mount = stream.node.mount;
550550
if (mount.type.syncfs) {
551-
return Asyncify.handleSleep((wakeUp) => {
552-
mount.type.syncfs(mount, false, (err) => wakeUp(err ? {{{ cDefs.EIO }}} : 0));
551+
return new Promise((resolve) => {
552+
mount.type.syncfs(mount, false, (err) => resolve(err ? {{{ cDefs.EIO }}} : 0));
553553
});
554554
}
555555
#endif // ASYNCIFY
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
addToLibrary({
2-
async_func__async: true,
3-
async_func: (value) => {
4-
return Asyncify.handleSleep((wakeUp) => {
5-
setTimeout(() => wakeUp(42), 0);
6-
});
7-
},
2+
async_func__async: 'auto',
3+
async_func: (value) => new Promise((resolve) => setTimeout(() => resolve(42), 0)),
84
});

0 commit comments

Comments
 (0)