Skip to content

Implement adaptive polling for streams#51

Merged
Just-Bamford merged 3 commits into
Sorokit:mainfrom
Stephan-Thomas:issue-14-adaptive-polling
Jun 24, 2026
Merged

Implement adaptive polling for streams#51
Just-Bamford merged 3 commits into
Sorokit:mainfrom
Stephan-Thomas:issue-14-adaptive-polling

Conversation

@Stephan-Thomas

@Stephan-Thomas Stephan-Thomas commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Adaptive Polling for Account and Transaction Streams

Summary

This PR implements adaptive polling for both streamAccount() and streamTransactions() to improve efficiency and responsiveness.

Previously, both streams used a fixed polling interval regardless of activity. This could lead to unnecessary requests for inactive accounts and delayed updates for highly active accounts. With adaptive polling, intervals now adjust automatically based on recent activity.

Changes

Adaptive Polling

Added adaptive interval management to:

  • src/account/streamAccount.ts
  • src/transaction/streamTransactions.ts

The stream now tracks consecutive polls without changes and adjusts the polling interval accordingly:

  • If activity is detected, the interval decreases (down to minIntervalMs).
  • If no activity is detected for a configured number of polls, the interval increases (up to maxIntervalMs).

Configuration

Added optional configuration fields:

{
  minIntervalMs?: number;
  maxIntervalMs?: number;
  adaptiveThreshold?: number;
}

These settings allow consumers to control adaptive polling behavior while preserving existing functionality.

Backward Compatibility

Adaptive polling is optional. Existing implementations that rely on fixed polling intervals continue to work without modification.

Testing

Added test coverage for:

  • Interval decreases when activity is detected.
  • Interval increases after consecutive inactive polls.
  • Minimum interval boundary enforcement.
  • Maximum interval boundary enforcement.
  • Adaptive threshold behavior.
  • Backward compatibility with existing fixed-interval configurations.

Benefits

  • Faster updates for active accounts and transaction streams.
  • Reduced bandwidth and API usage during inactivity.
  • Improved scalability when monitoring large numbers of streams.

Related Issue

Closes #14

@drips-wave

drips-wave Bot commented Jun 23, 2026

Copy link
Copy Markdown

@Stephan-Thomas 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

@Just-Bamford

Copy link
Copy Markdown
Collaborator

@Stephan-Thomas write a clear and detailed description for your pull request. and the CI test also fix that

@Just-Bamford Just-Bamford merged commit 5f84524 into Sorokit:main Jun 24, 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

Development

Successfully merging this pull request may close these issues.

Implement adaptive polling interval for account and transaction streams

2 participants