Skip to content

feat: guard sync-over-async bridge for WASM compatibility#10

Merged
MarcelRoozekrans merged 2 commits intomainfrom
feat/wasm-safe-no-sync-bridge
Mar 27, 2026
Merged

feat: guard sync-over-async bridge for WASM compatibility#10
MarcelRoozekrans merged 2 commits intomainfrom
feat/wasm-safe-no-sync-bridge

Conversation

@MarcelRoozekrans
Copy link
Copy Markdown
Owner

@MarcelRoozekrans MarcelRoozekrans commented Mar 22, 2026

Summary

  • Sync methods on abstract base classes now check OperatingSystem.IsBrowser() before calling .GetAwaiter().GetResult()
  • On WASM/browser: throws PlatformNotSupportedException with a message pointing to the async counterpart
  • On server/.NET: sync bridge continues to work as before
  • No breaking change for server-side consumers

How it works

A shared SyncBridge.ThrowIfBrowser() guard is called at the top of every sync method:

public void Open()
{
    SyncBridge.ThrowIfBrowser(nameof(OpenAsync));
    OpenCoreAsync(CancellationToken.None).GetAwaiter().GetResult();
}

What's guarded

Class Sync methods
AsyncDbConnection Open(), Close(), BeginTransaction(), ChangeDatabase(), Dispose()
AsyncDbCommand ExecuteReader(), ExecuteNonQuery(), ExecuteScalar(), Prepare()
AsyncDbDataReader Read(), NextResult(), Close(), Dispose()
AsyncDbTransaction Commit(), Rollback(), Dispose()
AsyncDataAdapter Fill(), Update()

Not affected

Adapter classes (AdapterDbConnection, etc.) override sync methods with direct delegation to the inner provider's native sync implementation.

Test plan

  • All 216 tests pass (sync bridge still works on non-WASM)
  • No test changes needed — original sync tests pass as before

🤖 Generated with Claude Code

@MarcelRoozekrans MarcelRoozekrans force-pushed the feat/wasm-safe-no-sync-bridge branch from c967324 to 6ae497f Compare March 22, 2026 19:06
@MarcelRoozekrans MarcelRoozekrans changed the title feat!: remove sync-over-async bridge for WASM compatibility feat: guard sync-over-async bridge for WASM compatibility Mar 22, 2026
Sync methods on abstract base classes now check OperatingSystem.IsBrowser()
and throw PlatformNotSupportedException on WASM/browser platforms where
blocking on async would deadlock. On server/.NET runtimes, the sync bridge
continues to work as before via .GetAwaiter().GetResult().

Guard applied to:
- AsyncDbConnection: Open, Close, BeginTransaction, ChangeDatabase, Dispose
- AsyncDbCommand: ExecuteReader, ExecuteNonQuery, ExecuteScalar, Prepare
- AsyncDbDataReader: Read, NextResult, Close, Dispose
- AsyncDbTransaction: Commit, Rollback, Dispose
- AsyncDataAdapter: Fill, Update

Adapter classes (AdapterDbConnection, etc.) are NOT affected — they override
sync methods with direct delegation to the inner provider's native sync
implementation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@MarcelRoozekrans MarcelRoozekrans force-pushed the feat/wasm-safe-no-sync-bridge branch from 6ae497f to fd43b2c Compare March 27, 2026 10:55
@MarcelRoozekrans MarcelRoozekrans merged commit 773dc24 into main Mar 27, 2026
1 check passed
@MarcelRoozekrans MarcelRoozekrans deleted the feat/wasm-safe-no-sync-bridge branch March 29, 2026 16:41
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