Skip to content

Consolidate threading APIs and add WebAssembly async fallbacks - #3

Draft
kudit wants to merge 1 commit into
mainfrom
agent/consolidate-threading-apis
Draft

Consolidate threading APIs and add WebAssembly async fallbacks#3
kudit wants to merge 1 commit into
mainfrom
agent/consolidate-threading-apis

Conversation

@kudit

@kudit kudit commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Scope

This draft PR is intentionally separate from the TestCase/Swift Testing PR.

It begins the threading API consolidation by adding:

  • an awaited, value-returning Compatibility.main overload for places currently using MainActor.run;
  • cooperative asynchronous Compatibility.background fallbacks for full-runtime WebAssembly;
  • an asynchronous WebAssembly sleep(seconds:) spelling while retaining the existing synchronous compatibility call for review and deprecation planning;
  • matching Task.background and Task.sleep(seconds:) wrappers on WebAssembly.

Important design distinctions

  • The existing main { } API remains fire-and-forget. The new await Compatibility.main { } overload waits for completion and can return a value.
  • WebAssembly supports Swift async syntax in the full runtime, but a generic host does not guarantee detached threads, Dispatch, or a suspending timer. The background fallback is therefore cooperative, and sleep currently warns and returns immediately until a host timer is supplied.
  • Throwing and nonthrowing awaited background work cannot necessarily collapse into one rethrows implementation when threaded hosts await Task.detached(...).value.
  • Optional-returning overloads should be removable because a generic Result may itself be optional.

Follow-up work within this draft

During review, consolidate the existing duplicate implementations in Threading.swift, deprecate obsolete spellings where source compatibility warrants it, and simplify Application.track to use the shared wrappers without a broad arch(wasm32) call-site branch.

Validation required

This is a draft because the final overload set must be compiled on Apple, Linux, and WebAssembly targets before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant