Skip to content

Add awaited main and WebAssembly async threading fallbacks - #3

Open
kudit wants to merge 1 commit into
agent/improve-test-infrastructurefrom
agent/consolidate-threading-apis
Open

Add awaited main and WebAssembly async threading fallbacks#3
kudit wants to merge 1 commit into
agent/improve-test-infrastructurefrom
agent/consolidate-threading-apis

Conversation

@kudit

@kudit kudit commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Purpose

PR #2 improves reusable test execution and Swift Testing integration. It does not add the missing asynchronous threading APIs covered here.

This PR adds a focused companion file with:

  • an awaited, value-returning Compatibility.main overload for code that currently calls MainActor.run directly;
  • cooperative asynchronous Compatibility.background overloads for full-runtime WebAssembly;
  • a generic nonthrowing result overload that also handles optional results without a separate duplicate API;
  • a throwing result overload matching the threaded-host API shape;
  • an asynchronous WebAssembly Compatibility.sleep(seconds:) spelling that reports the absence of a host timer and returns immediately;
  • matching Task.background and Task.sleep(seconds:) conveniences on WebAssembly.

Design boundaries

  • The existing main { } remains fire-and-forget and deployment-compatible. The new awaited overload waits for completion and can return a value.
  • The synchronous, dispatch-backed, delayed, and existing threaded-host implementations remain in Threading.swift.
  • WebAssembly scheduling is cooperative. These APIs do not claim detached-thread or parallel execution.
  • A generic WebAssembly host does not guarantee a suspending timer, so async sleep currently warns and returns immediately rather than pretending to delay.
  • Application.track keeps its existing platform-specific branch; rewriting it is not required for these APIs to be useful or correct.

Review and validation

The implementation is code-complete for review. Before merge:

This PR should remain separate from PR #2 and can be squash-merged after validation.

@kudit kudit changed the title Consolidate threading APIs and add WebAssembly async fallbacks Add awaited main and WebAssembly async threading fallbacks Jul 31, 2026
@kudit
kudit changed the base branch from main to agent/improve-test-infrastructure July 31, 2026 12:02
@kudit
kudit force-pushed the agent/consolidate-threading-apis branch from 9c2ffe8 to abca2f5 Compare July 31, 2026 12:03
@kudit
kudit marked this pull request as ready for review July 31, 2026 12:03
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