@@ -124,13 +124,20 @@ _Static_assert(sizeof(__wasi_iovec_t) == IOVEC_T_SIZE,
124124// If the stream has a readAsync handler, read to buffer defined in iovs, write
125125// number of bytes read to *nread, and return a promise that resolves to the
126126// errno. Otherwise, return null.
127+ //
128+ // Reading from an async input device and poll() suspend the wasm stack
129+ // instead of blocking when main() runs under WebAssembly.promising, which
130+ // Programs/emscripten_beforemain.c arranges for the interpreter. An embedder
131+ // running its own promising entry point opts in with
132+ // Module.Py_EmscriptenStackSwitching = true;
133+ // Otherwise these calls keep their synchronous behavior.
127134EM_JS_MACROS (__externref_t , __maybe_fd_read_async , (
128135 __wasi_fd_t fd ,
129136 const __wasi_iovec_t * iovs ,
130137 size_t iovcnt ,
131138 __wasi_size_t * nread
132139), {
133- if (!WebAssembly . promising ) {
140+ if (!Module . Py_EmscriptenStackSwitching ) {
134141 return null ;
135142 }
136143 var stream ;
@@ -214,7 +221,7 @@ _Static_assert(offsetof(struct pollfd, revents) == 6, "Unepxected pollfd struct
214221_Static_assert (sizeof (struct pollfd ) == 8 , "Unepxected pollfd struct layout" );
215222
216223EM_JS_MACROS (__externref_t , __maybe_poll_async , (intptr_t fds , int nfds , int timeout ), {
217- if (!WebAssembly . promising ) {
224+ if (!Module . Py_EmscriptenStackSwitching ) {
218225 return null ;
219226 }
220227 return (async function () {
0 commit comments