Skip to content

[browser][coreCLR] async main, thread pool, timers - #120976

Merged
pavelsavara merged 53 commits into
dotnet:mainfrom
pavelsavara:browser_async_main
Nov 4, 2025
Merged

[browser][coreCLR] async main, thread pool, timers#120976
pavelsavara merged 53 commits into
dotnet:mainfrom
pavelsavara:browser_async_main

Conversation

@pavelsavara

@pavelsavarapavelsavara commented Oct 22, 2025

Copy link
Copy Markdown
Member

work in progress:

  • -sEXIT_RUNTIME=0 for coreRun too
  • don't call coreclr_shutdown2_func in coreRun/browserHost
  • new AsyncHelpers.Browser.cs with
    • ExecuteAsyncEntryPoint that would call SystemJS_RejectMainPromise or SystemJS_ResolveMainPromise
  • change Assembly::GetEntryPoint to find original async Main()
    • the roslyn wrapper contains blocking TaskAwaiter<int>.GetResult() which is not possible on ST browser.
    • use MemberLoader::FindMethodByName by original name, but ignoring return type
  • change ValidateMainMethod to allow for signatures with Task or Task<int>
    • detect new CorEntryPointType.EntryManagedMainAsync and CorEntryPointType.EntryManagedMainAsyncVoid
  • new SystemJS_ExecuteTimerCallback and SystemJS_ExecuteBackgroundJobCallback
    • ideally this would be [UnmanagedCallersOnly]
    • into src\coreclr\vm\wasm\helpers.cpp and src\coreclr\vm\corelib.h for now

Fixes#120212
Fixes#120211
Fixes#121046

This work with the PR

publicstaticasyncTask<int>Main(){Console.WriteLine("Hello, World! "+DateTime.Now);awaitTask.Delay(1000);Console.WriteLine("After Task.Delay() "+DateTime.Now);return42;}

TODO

  • implement and test also Task Main() of void signature.
  • make sure that synchronous main still works
  • test exception marshaling
  • fix browserHost
  • test Release version JS name mangling
  • process commandline args

@pavelsavarapavelsavara added this to the 11.0.0 milestone Oct 22, 2025
@pavelsavarapavelsavara self-assigned this Oct 22, 2025
@pavelsavarapavelsavara added arch-wasm WebAssembly architecture area-System.Threading os-browser Browser variant of arch-wasm labels Oct 22, 2025
Comment threadsrc/coreclr/vm/siginfo.cpp Outdated
Comment threadsrc/coreclr/vm/corhost.cpp Outdated
Comment threadsrc/native/libs/System.Native.Browser/native/main.ts Outdated
Comment threadsrc/native/libs/System.Native.Browser/native/index.ts
Comment threadsrc/native/corehost/browserhost/libBrowserHost.footer.js Outdated
Comment threadsrc/coreclr/vm/assembly.cpp Outdated
Comment threadsrc/coreclr/vm/assembly.cpp Outdated
Comment threadsrc/coreclr/vm/assembly.cpp
Comment threadsrc/coreclr/vm/assembly.cpp Outdated
Comment threadsrc/coreclr/vm/assembly.cpp Outdated
pavelsavaraand others added 9 commits October 23, 2025 10:48
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
pavelsavaraand others added 7 commits October 23, 2025 10:58
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@pavelsavara

Copy link
Copy Markdown
MemberAuthor

is there more feedback ?

Comment threadsrc/coreclr/vm/assembly.cpp Outdated
Comment threadsrc/coreclr/vm/assembly.cpp Outdated
Comment threadsrc/coreclr/vm/assembly.cpp Outdated
Comment threadsrc/coreclr/vm/assembly.cpp Outdated
…erServices/AsyncHelpers.NonBrowser.cs
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
pavelsavaraand others added 4 commits November 3, 2025 18:26
…erServices/AsyncHelpers.NonBrowser.cs
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
…erServices/AsyncHelpers.NonBrowser.cs
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>

@gewarrengewarren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some doc suggestions.

Comment threadsrc/coreclr/vm/assembly.cpp Outdated
@jkotas

Copy link
Copy Markdown
Member

LGTM (the parts that I understand). Somebody with understanding of the JavaScript layer should review and signoff on that part.

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/ba-g CI timeouts and #114924

@pavelsavara
pavelsavara merged commit 8dbf912 into dotnet:mainNov 4, 2025
147 of 156 checks passed
@pavelsavara
pavelsavara deleted the browser_async_main branch November 4, 2025 17:06
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Dec 5, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasmWebAssembly architecturearea-System.Threadingos-browserBrowser variant of arch-wasm

Projects

None yet

9 participants

@pavelsavara@jkotas@333fred@stephentoub@radekdoulik@maraf@gewarren@AaronRobinsonMSFT