Skip to content

Enhancement: Add AsyncSequence wrapper for fetchRecordChanges streaming #200

@leogdion

Description

@leogdion

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 AsyncThrowingStream internally
  • Maintain sync token state between pages
  • Handle moreComing flag automatically
  • Support cancellation mid-stream
  • Add tests for cancellation and error scenarios

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions