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

Allow passing Infinity to waitFor as timeout #3215

Merged
merged 7 commits into from
Apr 15, 2022

Conversation

tom-sherman
Copy link
Contributor

@tom-sherman tom-sherman commented Apr 11, 2022

Closes #3214

WIP for now as I need figure out how to write a test for this, any pointers?

@changeset-bot
Copy link

changeset-bot bot commented Apr 11, 2022

🦋 Changeset detected

Latest commit: 1d6fc62

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate Patch

Not sure what this means? Click here to learn what changesets are.

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

@ghost
Copy link

ghost commented Apr 11, 2022

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 11, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1d6fc62:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration
magical-leakey-686h2e Issue #3214

rej(new Error(`Timeout of ${resolvedOptions.timeout} ms exceeded`));
}, resolvedOptions.timeout);
const handle =
resolvedOptions.timeout === Infinity
Copy link
Member

Choose a reason for hiding this comment

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

do you perhaps have a link that would mention the valid max value for this? It seems that Number.MAX_SAFE_INTEGER also calls this immediately

Copy link
Contributor Author

@tom-sherman tom-sherman Apr 11, 2022

Choose a reason for hiding this comment

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

I read that it's implemented using a 32bit unsigned int in most browsers, assumed that the max value was un-specced.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@Andarist Andarist Apr 15, 2022

Choose a reason for hiding this comment

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

I wonder if, in the next major version, the Infinity shouldn't be the default. cc @davidkpiano

It seems to be less quirky to configure an explicit timeout manually than to disable the builtin one.

@tom-sherman tom-sherman changed the title Allow passing Infinity to as waitFor timeout Allow passing Infinity to waitFor as timeout Apr 12, 2022
@Andarist
Copy link
Member

WIP for now as I need figure out how to write a test for this, any pointers?

You could create a Promise.race between your waitFor and some short-lived setTimeout (wrapped in a promise). Just to ensure that the waitFor doesn't reject immediately

tom-sherman and others added 3 commits April 12, 2022 11:32
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@tom-sherman tom-sherman marked this pull request as ready for review April 14, 2022 15:28
@Andarist Andarist merged commit 44c66e7 into statelyai:main Apr 15, 2022
@github-actions github-actions bot mentioned this pull request Apr 15, 2022
@tom-sherman tom-sherman deleted the waitfor-infinity branch April 15, 2022 14:18
nevilm-lt pushed a commit to nevilm-lt/xstate that referenced this pull request Apr 22, 2022
* Allow passing `Infinity` to as `waitFor` timeout

* Add changeset

* Add dev warning for negative timeouts

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Format

* Add test

* Simplify casting situation in `waitFor`

* Update .changeset/cool-ducks-pretend.md

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.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.

Bug: Timeout of Infinity causes waitFor to reject immediately
3 participants