Skip to content

Conversation

@dbolotin
Copy link
Member

  • Implement useAsyncPolling composable for async polling with controlled timing
  • Uses setTimeout (not setInterval) to wait for async callback completion
  • Supports minInterval (time between starts) and minDelay (delay after completion)
  • Integrates AbortController for proper cancellation
  • Provides pause/resume controls with isActive state
  • Includes error handling with lastError ref and pauseOnError option
  • Add comprehensive test suite with 27 tests covering all features
  • Export from uikit package

- Implement useAsyncPolling composable for async polling with controlled timing
- Uses setTimeout (not setInterval) to wait for async callback completion
- Supports minInterval (time between starts) and minDelay (delay after completion)
- Integrates AbortController for proper cancellation
- Provides pause/resume controls with isActive state
- Includes error handling with lastError ref and pauseOnError option
- Add comprehensive test suite with 27 tests covering all features
- Export from uikit package
@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2025

⚠️ No Changeset found

Latest commit: 48a8f03

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dbolotin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new useAsyncPolling composable to the uikit package, providing a robust and flexible solution for asynchronous polling in Vue applications. It offers precise control over polling intervals, handles callback completion before scheduling the next iteration, and includes built-in mechanisms for cancellation, pausing, resuming, and comprehensive error management.

Highlights

  • New Composable: Implemented the useAsyncPolling composable for managing asynchronous polling with controlled timing.
  • Timing Control: The composable uses setTimeout (not setInterval) to ensure each async callback completes before the next is scheduled, preventing overlapping executions. It supports minInterval (time between starts) and minDelay (delay after completion).
  • Cancellation: Integrates AbortController for proper cancellation of ongoing asynchronous operations when polling is paused, resumed, or the component is unmounted.
  • Control Mechanisms: Provides pause and resume functions, along with an isActive state, to manage the polling lifecycle.
  • Error Handling: Includes robust error handling with a lastError ref to store any encountered errors and a pauseOnError option to automatically stop polling upon error.
  • Test Coverage: A comprehensive test suite with 27 tests has been added, covering all features and edge cases of the useAsyncPolling composable.
  • Export: The new composable is exported from the uikit package, making it available for use across the application.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new useAsyncPolling composable, which provides a robust mechanism for asynchronous polling with fine-grained control over timing, cancellation, and error handling. The implementation is well-structured, thoroughly documented, and accompanied by a comprehensive test suite. My review focuses on improving the clarity of the public API documentation and enhancing the maintainability of the tests. I've suggested a minor update to the JSDoc for the resume function to make its behavior more explicit, and a refactoring of a test case to improve its readability.

Comment on lines +501 to +521
it('should not schedule next iteration if paused during callback', async () => {
let shouldPause = false;
const callback = vi.fn(async () => {
await new Promise((resolve) => setTimeout(resolve, 30));
});

const { pause } = useAsyncPolling(callback, { minInterval: 100 });

await vi.advanceTimersByTimeAsync(100);
expect(callback).toHaveBeenCalledTimes(1);

shouldPause = true;
await vi.advanceTimersByTimeAsync(100);

if (shouldPause) {
pause();
}

await vi.advanceTimersByTimeAsync(200);
expect(callback).toHaveBeenCalledTimes(2);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test case is functionally correct, but its implementation is a bit confusing and could be simplified for better readability and maintainability. The shouldPause variable is redundant as it's always true when the if condition is checked. The flow of advancing timers and then pausing can be made more direct and easier to understand.

    it('should not schedule next iteration if paused during callback', async () => {
      const callback = vi.fn(async () => {
        await new Promise((resolve) => setTimeout(resolve, 30));
      });

      const { pause } = useAsyncPolling(callback, { minInterval: 100 });

      await vi.advanceTimersByTimeAsync(100);
      expect(callback).toHaveBeenCalledTimes(1);

      await vi.advanceTimersByTimeAsync(100);
      expect(callback).toHaveBeenCalledTimes(2);

      pause();

      await vi.advanceTimersByTimeAsync(200);
      expect(callback).toHaveBeenCalledTimes(2);
    });

* - Set isActive to true
* - Clear lastError
* - Execute the callback immediately if immediateCallback is true
* - Schedule the next iteration
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The phrase 'Schedule the next iteration' is a bit ambiguous. When resume() is called and immediateCallback is false, the current implementation schedules the first execution after waiting for the full minInterval. This might be surprising to a developer who expects polling to resume more quickly. It would be beneficial to make this behavior explicit in the documentation to improve clarity and prevent potential misuse.

Suggested change
* - Schedule the next iteration
* - Schedule the first iteration after `minInterval` if `immediateCallback` is false

- Add pause function to callback options for easy access from within callback
- No need to capture returned pause function separately
- Allows conditional pausing based on callback results
- Add 3 new tests verifying pause-in-callback functionality
- Update documentation with example and explanation
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.

2 participants