Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wait for plan selection #1547

Merged
merged 2 commits into from
Sep 16, 2024
Merged

feat: wait for plan selection #1547

merged 2 commits into from
Sep 16, 2024

Conversation

fforbeck
Copy link
Member

@fforbeck fforbeck commented Sep 16, 2024

Add wait() Method to AccountPlan Class

Summary

This PR introduces a new wait() method to the AccountPlan class, which simplifies the process of waiting for a payment plan to be selected. By integrating configurable polling intervals, timeouts, and abort signals, the method abstracts the common logic required in this scenario, making it easier for developers to implement and customize their workflows.

Changes

  • New wait() Method:
    • The wait() method repeatedly checks the account's payment plan status at a given interval until:
      • A valid plan is selected.
      • The timeout is reached.
      • The operation is aborted using an AbortSignal.
    • Available options:
      • interval (default: 1000ms): Sets the polling interval.
      • timeout (default: 15 minutes): Defines the maximum wait time.
      • signal: An optional AbortSignal to allow for cancellation.
    • This method improves the developer experience by abstracting the repetitive logic required to wait for a payment plan and offering flexibility through configurable options.

How to Test

  1. Run the test suite with npm run build && npm run test.
  2. Ensure all existing tests pass.
  3. Verify that the new test cases for the wait() method in account.test.js are passing, including tests for:
    • Successful payment plan selection.
    • Timeout errors.
    • Aborted operations.

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

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

🚀 This is awesome.

I think this could be merged as is but personally I think we should increase the timeout to 15 minutes as mentioned in comment.

packages/w3up-client/src/account.js Outdated Show resolved Hide resolved
@fforbeck fforbeck merged commit 7fdee77 into main Sep 16, 2024
4 checks passed
@fforbeck fforbeck deleted the wait-for-payment branch September 16, 2024 15:30
fforbeck pushed a commit that referenced this pull request Sep 16, 2024
🤖 I have created a release *beep* *boop*
---


##
[16.1.0](w3up-client-v16.0.0...w3up-client-v16.1.0)
(2024-09-16)


### Features

* **client:** optional account recovery
([#1546](#1546))
([ea02adb](ea02adb))
* wait for plan selection
([#1547](#1547))
([7fdee77](7fdee77))


### Other Changes

* Add `pnpm dev` to watch-build all packages
([#1533](#1533))
([07970ef](07970ef))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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