@@ -426,12 +426,10 @@ addToLibrary({
426
426
//
427
427
// This is particularly useful for native JS `async` functions where the
428
428
// returned value will "just work" and be passed back to C++.
429
- handleAsync ( startAsync ) {
430
- return Asyncify . handleSleep ( ( wakeUp ) => {
431
- // TODO: add error handling as a second param when handleSleep implements it.
432
- startAsync ( ) . then ( wakeUp ) ;
433
- } ) ;
434
- } ,
429
+ handleAsync : ( startAsync ) => Asyncify . handleSleep ( ( wakeUp ) => {
430
+ // TODO: add error handling as a second param when handleSleep implements it.
431
+ startAsync ( ) . then ( wakeUp ) ;
432
+ } ) ,
435
433
436
434
#elif ASYNCIFY == 2
437
435
//
@@ -452,9 +450,7 @@ addToLibrary({
452
450
{ { { runtimeKeepalivePop ( ) ; } } }
453
451
}
454
452
} ,
455
- handleSleep ( startAsync ) {
456
- return Asyncify . handleAsync ( ( ) => new Promise ( startAsync ) ) ;
457
- } ,
453
+ handleSleep : ( startAsync ) => Asyncify . handleAsync ( ( ) => new Promise ( startAsync ) ) ,
458
454
makeAsyncFunction ( original ) {
459
455
#if ASYNCIFY_DEBUG
460
456
dbg ( 'asyncify: makeAsyncFunction for' , original ) ;
@@ -466,33 +462,24 @@ addToLibrary({
466
462
467
463
emscripten_sleep__deps : [ '$safeSetTimeout' ] ,
468
464
emscripten_sleep__async : true ,
469
- emscripten_sleep : ( ms ) => {
470
- // emscripten_sleep() does not return a value, but we still need a |return|
471
- // here for stack switching support (ASYNCIFY=2). In that mode this function
472
- // returns a Promise instead of nothing, and that Promise is what tells the
473
- // wasm VM to pause the stack.
474
- return Asyncify . handleSleep ( ( wakeUp ) => safeSetTimeout ( wakeUp , ms ) ) ;
475
- } ,
465
+ emscripten_sleep : ( ms ) => Asyncify . handleSleep ( ( wakeUp ) => safeSetTimeout ( wakeUp , ms ) ) ,
476
466
477
467
emscripten_wget_data__deps : [ '$asyncLoad' , 'malloc' ] ,
478
468
emscripten_wget_data__async : true ,
479
- emscripten_wget_data : ( url , pbuffer , pnum , perror ) => {
480
- return Asyncify . handleSleep ( ( wakeUp ) => {
481
- /* no need for run dependency, this is async but will not do any prepare etc. step */
482
- asyncLoad ( UTF8ToString ( url ) ) . then ( ( byteArray ) => {
483
- // can only allocate the buffer after the wakeUp, not during an asyncing
484
- var buffer = _malloc ( byteArray . length ) ; // must be freed by caller!
485
- HEAPU8 . set ( byteArray , buffer ) ;
486
- { { { makeSetValue ( 'pbuffer' , 0 , 'buffer' , '*' ) } } } ;
487
- { { { makeSetValue ( 'pnum' , 0 , 'byteArray.length' , 'i32' ) } } } ;
488
- { { { makeSetValue ( 'perror' , 0 , '0' , 'i32' ) } } } ;
489
- wakeUp ( ) ;
490
- } , ( ) => {
491
- { { { makeSetValue ( 'perror' , 0 , '1' , 'i32' ) } } } ;
492
- wakeUp ( ) ;
493
- } ) ;
494
- } ) ;
495
- } ,
469
+ emscripten_wget_data : ( url , pbuffer , pnum , perror ) => Asyncify . handleAsync ( async ( ) => {
470
+ /* no need for run dependency, this is async but will not do any prepare etc. step */
471
+ try {
472
+ const byteArray = await asyncLoad ( UTF8ToString ( url ) ) ;
473
+ // can only allocate the buffer after the wakeUp, not during an asyncing
474
+ var buffer = _malloc ( byteArray . length ) ; // must be freed by caller!
475
+ HEAPU8 . set ( byteArray , buffer ) ;
476
+ { { { makeSetValue ( 'pbuffer' , 0 , 'buffer' , '*' ) } } } ;
477
+ { { { makeSetValue ( 'pnum' , 0 , 'byteArray.length' , 'i32' ) } } } ;
478
+ { { { makeSetValue ( 'perror' , 0 , '0' , 'i32' ) } } } ;
479
+ } catch ( err ) {
480
+ { { { makeSetValue ( 'perror' , 0 , '1' , 'i32' ) } } } ;
481
+ }
482
+ } ) ,
496
483
497
484
emscripten_scan_registers__deps : [ '$safeSetTimeout' ] ,
498
485
emscripten_scan_registers__async : true ,
0 commit comments