feat(realtime): improve task lifecycle management and expose public APIs #851
+227
−38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the Realtime implementation with better task lifecycle management, enhanced cancellation handling, and exposes necessary public APIs. It includes both the implementation changes and comprehensive tests.
Changes
Implementation Changes
RealtimeChannelV2.swift:
topicproperty public for external accessconfigproperty publicly readable (with private setter) for inspectionRealtimeClientV2.swift:
listenForMessages()before creating new message tasksstartHeartbeating()before creating new heartbeat tasksheartbeatAsyncStream initialization (remove redundant type casting)WebSocketTransporttypealias for better readabilityTests Added
RealtimeChannelTests.swift (2 new tests):
testTopicIsPubliclyAccessible: Verifies thetopicproperty is publicly accessibletestConfigIsPubliclyReadable: Verifies theconfigproperty is publicly readableRealtimeTests.swift (4 new tests):
testListenForMessagesCancelsExistingTask: VerifieslistenForMessages()properly cancels previous tasks on reconnectiontestStartHeartbeatingCancelsExistingTask: VerifiesstartHeartbeating()properly cancels previous tasks on reconnectiontestMessageProcessingRespectsCancellation: Verifies message processing respects task cancellationtestMultipleReconnectionsHandleTaskLifecycleCorrectly: Verifies multiple connect/disconnect cycles manage task lifecycle correctlyBenefits
topicand inspectconfigon channel instancesTest Results
✅ All 6 new tests pass
✅ All 133 existing Realtime tests continue to pass
✅ No regressions introduced
Breaking Changes
None. The changes are backward compatible:
🤖 Generated with Claude Code