Skip to content

Conversation

@dgozman
Copy link
Contributor

@dgozman dgozman commented Jun 12, 2025

This introduces a "strict" mode to Progress, where it waits until the action completes instead of racing against a timeout.

The action is responsible to terminate upon progress being aborted. The "rule of thumb" is - whenever a method accepts a progress, it must either succeed before the progress aborts or throw an error.

To support this new scheme, some new APIs have been added to the progress:

  • race() to race any promise against the abort. Useful for things like evaluate() that do not change the state of the page, or single protocol commands. Many places now use this method to ensure they terminate when the progress is aborted.
  • raceWithCleanup() that combines race() and cleanupWhenAborted().
  • wait() that waits for a timeout, but is aware of progress abort.

References #35987.

This introduces a "strict" mode to `Progress`, where it waits
until the action completes instead of racing against a timeout.

The action is responsible to terminate upon progress being aborted.
To support this, some new APIs have been added to the progress:
- `race()` to race any promise against the abort. Useful for things
  like `evaluate()` that do not change the state of the page, or
  single protocol commands.
- `raceWithCleanup()` that combines `race()` and `cleanupWhenAborted()`.
- `wait()` that waits for a timeout, but is aware of progress abort.
@dgozman dgozman requested a review from yury-s June 12, 2025 15:59
@github-actions
Copy link
Contributor

Test results for "tests 1"

4 flaky ⚠️ [chromium-library] › library/chromium/oopif.spec.ts:284:3 › should click @chromium-ubuntu-22.04-node20
⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:986:7 › cli codegen › should not throw csp directive violation errors @firefox-ubuntu-22.04-node18
⚠️ [webkit-library] › library/video.spec.ts:441:5 › screencast › should work for popups @webkit-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

39367 passed, 820 skipped
✔️✔️✔️

Merge workflow run.

},
raceWithCleanup: <T>(promise: Promise<T>, cleanup: (result: T) => any) => {
return progress.race(promise.then(result => {
progress.cleanupWhenAborted(() => cleanup(result));
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we run cleanup if the promise throws? Also, shouldn't cleanup be scheduled even if the promise is not finished?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to allow the result escape the progress scope when the operation is successful. A typical example is newContext() that wants to return the context on success, but close it when the operation fails.

@dgozman dgozman merged commit 357ebfe into microsoft:main Jun 16, 2025
29 of 31 checks passed
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