Skip to content

Improve polling#89

Merged
MattCCC merged 7 commits into
masterfrom
improve-polling
Jun 3, 2025
Merged

Improve polling#89
MattCCC merged 7 commits into
masterfrom
improve-polling

Conversation

@MattCCC

@MattCCC MattCCC commented Jun 2, 2025

Copy link
Copy Markdown
Owner

This pull request introduces a comprehensive overhaul of the polling functionality in the codebase. Key changes include the addition of new polling configurations, refactoring of polling logic to improve modularity and maintainability, and the introduction of unit tests to ensure robust behavior. These updates enhance flexibility, allow finer control over polling behavior, and improve code readability.

Polling Configuration Enhancements:

  • Added new options pollingDelay and maxPollingAttempts to the polling configuration, allowing a delay before each polling attempt and limiting the number of attempts. Updated the README.md to document these options. [1] [2] [3]

Refactoring of Polling Logic:

  • Introduced the withPolling function in src/polling-handler.ts to encapsulate polling logic, making it reusable and modular. This function supports polling intervals, delays, and maximum attempts.
  • Refactored createRequestHandler in src/request-handler.ts to delegate polling logic to withPolling, simplifying the request handler implementation. Removed redundant polling-related code. [1] [2] [3] [4] [5] [6]

Type Updates:

  • Updated the PollingFunction type and ExtendedRequestConfig interface in src/types/request-handler.ts to reflect the new polling options and ensure compatibility with the refactored logic. [1] [2]

Unit Tests for Polling:

  • Added unit tests for withPolling in test/polling-handler.spec.ts to validate polling behavior, including scenarios for delays, maximum attempts, and custom stop conditions.
  • Enhanced tests for createRequestHandler in test/request-handler.spec.ts to verify integration with the new polling functionality. [1] [2] [3]

Auxiliary Changes:

  • Updated linting configuration in package.json to include example files for better code quality enforcement.
  • Added a new polling example (example9) in docs/examples/examples.ts to demonstrate usage of the updated polling options. [1] [2]

@MattCCC MattCCC self-assigned this Jun 2, 2025
@MattCCC MattCCC requested a review from Copilot June 2, 2025 20:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the polling mechanism to allow finer control over how and when polling executes. Key changes include:

  • Introducing new polling configuration options (pollingDelay and maxPollingAttempts).
  • Refactoring polling logic into a separate withPolling function.
  • Updating tests and documentation to reflect these changes.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/request-handler.spec.ts Updates to timer usage and tests for polling behavior.
src/types/request-handler.ts Adds new pollingDelay and maxPollingAttempts options in type defs.
src/request-handler.ts Refactors polling logic by delegating to the new withPolling helper.
src/polling-handler.ts Introduces the withPolling function to manage polling retries.
README.md Updates documentation with examples for the new polling options.
Comments suppressed due to low confidence (1)

src/request-handler.ts:370

  • The new pollingDelay option is defined in the types and documentation but not utilized here. Consider passing mergedConfig.pollingDelay to withPolling (or incorporating it within the polling logic) to apply the intended delay before each polling attempt.
pollingInterval > 0 ? withPolling<FetchResponse<ResponseData, RequestBody, QueryParams, PathParams>>(doRequestOnce, pollingInterval, mergedConfig.shouldStopPolling, mergedConfig.maxPollingAttempts)

Comment thread README.md Outdated
@github-actions

github-actions Bot commented Jun 2, 2025

Copy link
Copy Markdown

size-limit report 📦

Path Size
dist/browser/index.mjs 3.93 KB (+1.34% 🔺)
dist/browser/index.global.js 4.1 KB (+1.55% 🔺)
dist/node/index.js 4.01 KB (+1.29% 🔺)

@MattCCC MattCCC requested a review from Copilot June 2, 2025 23:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR centralizes and enhances polling behavior in the request handler by introducing new configuration options, moving polling logic into its own utility, and updating tests and documentation.

  • Added pollingDelay and maxPollingAttempts options and removed the unused error parameter from shouldStopPolling.
  • Refactored polling into withPolling and updated createRequestHandler to use it.
  • Expanded unit tests for polling and refreshed documentation and examples to reflect new options.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/request-handler.spec.ts Adjusted timer setup and added infinite‐loop protection test.
test/polling-handler.spec.ts New unit tests covering withPolling scenarios.
src/types/request-handler.ts Updated PollingFunction type and added pollingDelay/maxPollingAttempts.
src/request-handler.ts Refactored to call withPolling instead of inline polling logic.
src/polling-handler.ts Introduced new withPolling function.
package.json Expanded lint scope to include example files.
docs/examples/examples.ts Added example9 demonstrating polling.
README.md Expanded polling section with new options and behaviors.
Comments suppressed due to low confidence (1)

test/request-handler.spec.ts:375

  • This test asserts on delayInvocation but it isn’t mocked or spied on, so the expectation will always fail. You should spy on or mock delayInvocation (e.g. using jest.spyOn) or adjust the assertion to reference the actual mock.
expect(delayInvocation).toHaveBeenCalledTimes(2);

Comment thread src/request-handler.ts
Comment thread README.md
Comment thread README.md Outdated
@MattCCC MattCCC requested a review from Copilot June 3, 2025 16:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request improves the polling functionality by adding new configuration options, refactoring the polling logic into a dedicated function, and updating documentation and tests to reflect these changes.

  • New polling options (pollingDelay, maxPollingAttempts) have been added and incorporated in the polling handler.
  • The polling logic has been refactored into a new withPolling function, and tests have been updated to validate these changes.
  • The documentation and examples have been expanded to explain the new polling options and their usage.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/request-handler.spec.ts Updated tests for polling behavior; note possible inconsistency in delay mock reference.
test/polling-handler.spec.ts Added comprehensive tests for the new withPolling function.
src/types/request-handler.ts Updated type definitions to remove the error parameter in shouldStopPolling.
src/request-handler.ts Refactored polling logic to use withPolling and updated deduplication handling.
src/polling-handler.ts Introduced withPolling function for centralized polling logic.
package.json Expanded linting scope to include example files.
docs/examples/examples.ts Added example9 to demonstrate new polling options.
README.md Updated documentation to include new polling options and usage.
Comments suppressed due to low confidence (2)

README.md:708

  • The documentation still mentions an 'error' parameter for shouldStopPolling, even though the updated signature accepts only (response, attempt). Please update the description to remove any reference to the error parameter.
A function to determine if polling should stop based on the response, error, or the current polling attempt number.

test/request-handler.spec.ts:375

  • There appears to be an inconsistency with the delay function mock: earlier the test referenced 'mockDelayInvocation' while here it uses 'delayInvocation'. Please ensure the tests consistently refer to the correct mock for clarity.
expect(delayInvocation).toHaveBeenCalledTimes(2);

@MattCCC MattCCC merged commit 278c155 into master Jun 3, 2025
8 checks passed
@MattCCC MattCCC deleted the improve-polling branch June 3, 2025 16:58
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.

3 participants