-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Today, .NET on WebAssembly is unable to implement clean support for cases where .NET APIs need to be synchronous, but they can only be implemented asynchronously inside a browser. Examples:
- Cryptography APIs
- Assembly loading (e.g., for lazy loading), where the assembly content must be fetched from the network
An upcoming standard should give us the option to solve these problems: https://v8.dev/blog/jspi, a.k.a. JSPI
JSPI works simply by suspending the WebAssembly runtime until a JS promise completes. Clearly this has the drawback that a UI would be frozen for this period, but that's no different from (say) a Windows Forms UI being suspended for the microseconds needed for a cryptography operation. In the case of lazy-loading an assembly there's more risk that the UI freeze could last for a human-noticeable delay, but presumably the developer could be given some JS-side callback where they can do whatever they want (such as showing a "please wait" UI).
This doesn't invalidate the need for multithreading, but gives us an escape hatch in the case of .NET synchronous APIs that we want to carry over into browsers because in a lot of cases they would work out fine.
cc @dotnet/aspnet-blazor-eng