Skip to content

Conversation

@spnkr
Copy link

@spnkr spnkr commented Jan 5, 2025

Adds an async version of .do(_:) so Then can handle asynchronous closures. It’s conditionally compiled and doesn’t break existing synchronous usage.

Changes

  • Introduces a new do(_:) with an async closure, gated by #if swift(>=5.5) && canImport(_Concurrency) and @available(iOS 13, macOS 10.15, etc.).
  • Leaves the original synchronous do(_:) untouched.

Why

Avoids "cannot pass async closure to parameter expecting synchronous function type" errors.

Allows writing:

await object.do {  
  await someAsyncCall() 
}

Compatibility

No breaking changes. Earlier Swift or platforms without concurrency continue using the sync do(_:).

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