Skip to content

Feat/async iterable iterator - #557

Merged
BigBen-7 merged 4 commits into
Lead-Studios:mainfrom
nafsonig:feat/AsyncIterableIterator
Aug 28, 2026
Merged

Feat/async iterable iterator#557
BigBen-7 merged 4 commits into
Lead-Studios:mainfrom
nafsonig:feat/AsyncIterableIterator

Conversation

@nafsonig

Copy link
Copy Markdown
Contributor

Summary

Summary of Changes

We've successfully implemented the streamEvents method for the VeriTix SDK that connects to Horizon SSE endpoints, which is much more efficient than the existing polling-based watchers. Here's what was done:

1. Added new types to src/types/index.ts

2. Implemented streamEvents method in src/client.ts

The method is an async generator (async *) that returns an AsyncIterableIterator<VeriTixEvent>, following the same pattern as existing watchers like watchEscrow. Key features:

  • Automatic Horizon URL resolution: Uses the correct Horizon URL based on the network (testnet/mainnet) or derives it from custom RPC URLs
  • Cross-environment compatibility: Works in both browsers (uses global EventSource) and Node.js (dynamically imports the eventsource package)
  • Exponential backoff reconnection: Automatically reconnects if the stream drops, with backoff that doubles each attempt up to the maximum
  • closes chore: add .editorconfig — enforce consistent indentation and line endings across editors #506
  • AbortSignal support: Properly cleans up the EventSource connection when the abort signal is triggered
  • Correct Horizon event parsing: Parses raw Horizon contract events into the standardized VeriTixEvent format, following Stellar's Horizon API specifications
  • Error handling: Skips invalid events and gracefully handles connection errors

3. Exported new types in src/index.ts

Added VeriTixEvent and StreamEventOptions to the public API exports so users can import them.

Usage Example

const controller = new AbortController();
// Stop streaming after 1 minute
setTimeout(() => controller.abort(), 60000);

for await (const event of client.streamEvents({ signal: controller.signal })) {
  console.log(`Received ${event.type} at ledger ${event.ledger}`);
  if (event.type === 'ticket_purchased') {
    console.log('New ticket sale!', event.data);
closes #507

  }
}

The implementation is complete and meets all the requirements: it uses Horizon SSE for efficient event streaming, parses events into the correct format, auto-reconnects with exponential backoff, and supports cancellation via AbortSignal.

Closes

Closes #

Checklist

  • Tests added or updated
  • Docs updated (JSDoc / README)
  • CHANGELOG.md updated under [Unreleased] (required by CI if src/ changed — see CONTRIBUTING.md)
  • API surface change is intentional, not accidental (public method signatures / exported types)
  • npm run build passes
  • npm test passes
  • npm run lint passes

@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@nafsonig Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@BigBen-7
BigBen-7 merged commit d869c5c into Lead-Studios:main Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants