Add async/await create methods for Observable and Infallible#2673
Add async/await create methods for Observable and Infallible#2673Woollim wants to merge 3 commits intoReactiveX:mainfrom
Conversation
- 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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
|
Hey @Woollim, This is a nice quality-of-life improvement but I'm not convinced it provides too much value, vs. Observable.create { observer in
Task { ...
observer.onNext(...)
}
}Or even using a subject/relay: let subject = BehaviorSubject ...
try await subject.onNext(myAsyncThing())
return subject.asObservable()Or, using the already-existing convenience helpers: asyncStream.asObservable()
Single.create { try await thing() }
// etc...I'm closing this for now but if you want to continue the discussion feel free to comment. |
|
Hey @freak4pc, Thanks for taking the time to review this older PR. TL;DR: Regarding
|
Summary
This PR adds new
createmethods for bothObservableandInfallibletypes that support Swift's async/await concurrency features, making it easier to create reactive streams from asynchronous operations.Changes
New Methods Added
Observable.createwith async/await supportElementObserverparameterInfallible.createwith async/await supportElementObserverparameterUsage Examples
This implementation was inspired by TCA's
runfunction for creating Effects from async operations.See: https://github.com/pointfreeco/swift-composable-architecture/blob/acd9bb8a7cf6e36a89d81a432c2e8eb3b1bb3771/Sources/ComposableArchitecture/Effect.swift#L87-L95