-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Overview
Add an AsyncSequence-based API for streaming record changes, providing a more ergonomic alternative to manual pagination with fetchRecordChanges().
Current API
// Manual pagination
let result = try await service.fetchRecordChanges(syncToken: token)
if result.moreComing {
let next = try await service.fetchRecordChanges(syncToken: result.syncToken)
}
// Or convenience method (loads all into memory)
let (records, token) = try await service.fetchAllRecordChanges()Proposed API
// Stream records as they're fetched
for try await record in service.recordChangesSequence(syncToken: token) {
process(record)
}
// Or with zone specification
for try await record in service.recordChangesSequence(
zoneID: .init(zoneName: "Articles"),
syncToken: token
) {
process(record)
}Benefits
- Memory efficient: Process records as they arrive without buffering
- Cancellable: Natural cancellation via AsyncSequence
- Ergonomic: Familiar Swift Concurrency patterns
- Backpressure: Consumer controls pacing
Implementation Notes
- Use
AsyncThrowingStreaminternally - Maintain sync token state between pages
- Handle
moreComingflag automatically - Support cancellation mid-stream
- Add tests for cancellation and error scenarios
Related
- Implemented in Fetching Database Changes (changes/database) #46 (fetchRecordChanges)
- Follow patterns from Swift Concurrency best practices
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request