Uh oh!
There was an error while loading. Please reload this page.
feat: add waitFor utility to wait for a duration - #302
Open
gomesalexandre wants to merge 1 commit into
Open
Conversation
Adds `waitFor(milliseconds)`, a promisified `setTimeout` for pausing execution in an async function. This helper is duplicated across many MetaMask projects (test-dapp, metamask-sdk, metamask-extension, ...), so it makes sense to consolidate it here. It lives in `time.ts` next to `Duration`/`inMilliseconds`, validates its input with the module's existing `assertIsNonNegativeInteger`, and composes with `inMilliseconds` for other durations, e.g. `waitFor(inMilliseconds(2, Duration.Second))`. closesMetaMask#160
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 freeto 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.
closes#160
what
Adds
waitFor(milliseconds), a promisifiedsetTimeoutfor pausing execution inside an async function. As the issue notes, this helper is reimplemented across many MetaMask projects (test-dapp, metamask-sdk, metamask-extension, metamask-desktop), so consolidating it here removes the duplication.how
src/time.tsalongsideDuration/inMilliseconds, since it waits for a durationassertIsNonNegativeInteger, consistent withinMillisecondsandtimeSincewaitFor); happy to rename towait/delayif you'd prefertests
Added unit tests covering the resolve-after-duration path (via jest fake timers), the zero-duration case, and rejection on a negative/non-integer input.
time.tsis at 100% coverage; updated theindex/nodeexport snapshots. Full suite (1988 tests),tsc/build,tsd, eslint and prettier all pass.Note
Cursor Bugbot is generating a summary for commit 2c0f4ab. Configure here.