Skip to content

Conversation

Woollim
Copy link

@Woollim Woollim commented Sep 5, 2025

Summary

This PR adds new create methods for both Observable and Infallible types that support Swift's async/await concurrency features, making it easier to create reactive streams from asynchronous operations.

Changes

New Methods Added

  • Observable.create with async/await support

    • Takes an async closure with an ElementObserver parameter
    • Supports throwing operations (emits error events on exceptions)
    • Provides task cancellation handling
  • Infallible.create with async/await support

    • Takes an async closure with an ElementObserver parameter
    • Non-throwing version for infallible operations
    • Provides task cancellation handling

Usage Examples

// Observable with async/await
let observable = Observable<String>.create { observer in
    let data = try await fetchDataFromAPI()
    observer(data)
    
    let moreData = try await fetchMoreData()
    observer(moreData)
}

// Infallible with async/await
let infallible = Infallible<Int>.create { observer in
    for i in 1...10 {
        await Task.yield() // Cooperative cancellation
        observer(i)
    }
}

This implementation was inspired by TCA's run function for creating Effects from async operations.
See: https://github.com/pointfreeco/swift-composable-architecture/blob/acd9bb8a7cf6e36a89d81a432c2e8eb3b1bb3771/Sources/ComposableArchitecture/Effect.swift#L87-L95

Woollim and others added 3 commits September 5, 2025 14:55
- Add Observable.create with async/await support
- Add Infallible.create with async/await support
- Both methods support detached tasks and custom priority
- Include proper Task cancellation handling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add test for Infallible.create with async support
- Add test for Observable.create with async support
- Tests verify proper value emission and completion

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add documentation for Observable.create with async/await
- Add documentation for Infallible.create with async/await

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
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