feat(mqtt-bridge): add continuous polling mode#383
Open
Conversation
Add optional 'mode' field to PollingConfig to support: - 'interval' (default): Poll at fixed intervals - 'continuous': Poll immediately after receiving response This enables maximum data throughput for time-sensitive applications.
Add test coverage for: - Continuous mode polls immediately (0ms delay) after response - Default mode remains interval-based when not specified - Backoff logic still applies in continuous mode - Recovery from backoff returns to continuous mode Tests currently fail - implementation follows in next commit.
Add continuous polling mode that polls devices with minimal delay (1ms) instead of waiting for the configured interval. This enables maximum data throughput for time-sensitive applications. Implementation: - Check polling mode in scheduleNextPoll() - Use 1ms delay for continuous mode (next event loop tick) - Use interval delay for interval mode (default) - Backoff logic applies to both modes when maxRetries exceeded The 1ms delay (vs 0ms) ensures: - Minimal latency while avoiding test infinite loops - Allows other event loop tasks to execute - Matches real-world setTimeout(fn, 0) behavior
Add Zod schema validation for the optional polling mode field: - Accepts 'interval' (default behavior) - Accepts 'continuous' (minimal delay between polls) - Rejects invalid mode values Test coverage: - Valid interval mode configuration - Valid continuous mode configuration - Invalid mode value rejection
Add documentation for the new polling mode configuration option: - Explain interval vs continuous modes - Show example configuration with continuous mode - Document the minimal 1ms delay for continuous polling Users can now configure devices for maximum throughput by using continuous mode, which polls immediately after receiving responses.
@ya-modbus/cli
@ya-modbus/device-profiler
@ya-modbus/driver-ex9em
@ya-modbus/driver-loader
@ya-modbus/driver-or-we-516
@ya-modbus/driver-sdk
@ya-modbus/driver-types
@ya-modbus/driver-xymd1
@ya-modbus/emulator
@ya-modbus/mqtt-bridge
@ya-modbus/transport
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Adds continuous polling mode that polls devices with minimal delay (1ms) instead of waiting for the configured interval. This enables maximum data throughput for time-sensitive applications where users want to read from devices as fast as possible.
Implementation
modefield toPollingConfigtype ('interval' | 'continuous')scheduleNextPoll()to use 1ms delay for continuous modeConfiguration Example
{ "deviceId": "sensor1", "driver": "@ya-modbus/driver-ex9em", "connection": { "type": "rtu", "port": "/dev/ttyUSB0", "baudRate": 9600, "slaveId": 1 }, "polling": { "interval": 2000, "mode": "continuous" } }Technical Details
Why 1ms instead of 0ms?
setTimeout(..., 0)behaviorBackoff Logic
maxRetriesandretryBackoffsettingsTesting
All 298 tests pass, including new tests for:
Breaking Changes
None - this is a backward-compatible feature addition.
Checklist