emscripten-core / emscripten-core/emscripten
preInit (and maybe onRuntimeInitialized?) should support Promises/async
- Lingua principale
- C++
- Stelle
- 27.6k
- Fork
- 3.6k
- Merge medio
- 1g 14h
- PR unite (30g)
- 125
Descrizione
Because of how async works in JS (your function just starts returning a Promise) it's easy for someone to make a preInit or onRuntimeInitialized handler async and not notice that the behavior is subtly wrong, introducing a race condition. Handling this by hand using runtime dependencies is a little tricky because of how promise fulfillment works (next event loop turn) vs how runtime dependencies work (as soon as they're all gone, the callback is invoked synchronously), so you can accidentally introduce a new race when doing it. If preInit (and potentially onRuntimeInitialized) were updated to notice if the handler returned a thenable it would be possible for all this to just work and it would reduce the risk of people adding races by misusing runtime dependencies or forgetting about them entirely.
I think implementing this would just mean changing the loop at the bottom of generated JS that runs preInit functions so that it notices thenables and chains off .then if it encounters one, and then do the final run invoke in the last callback.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia dal ciclo in fondo al JavaScript generato che esegue le funzioni preInit e analizza come lo segue l’invocazione finale del runtime. Determina come concatenare i thenable restituiti affinché l’avvio del runtime attenda il loro adempimento e valuta se onRuntimeInitialized debba ricevere lo stesso trattamento. Il lavoro è completato quando gli handler asincroni non introducono più una race condition all’avvio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, wasm
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100