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.
What is this?
Currently, tasks within the internal queue, including snapshots, are cancelable. This is done by utilizing generators as tasks. This PR takes that concept and uses it to make other core methods cancelable as well. Having these methods be cancelable will allow better handling of process termination in the CLI rather than relying on promises to completely settle.
While implementing this, I discovered that I had many hanging Chromium processes after several tests. This prompted me to tighten up some browser internals to alleviate it. Also while implementing this, the upload queue's concurrency was fixed to mirror the snapshot queue, and the
setConfig
method was updated to allow configuring the discovery concurrency after percy has already started.To make certain core methods cancelable, the queue's cancelable generators were refactored into a common util and used to reimplement the
waitFor
helper. Since this helper is provided to the browser duringexecute
, the newgeneratePromise
helper must also be provided. This helper wraps an async generator function to become thennable and cancelable. This helper was then used in core methods such asstart
,stop
, and others to allow them to be cancelable.While making the
stop
method cancelable, part of it was refactored into a newflush
method. In the future, this new method could also be used to flush snapshots from the queue when retries are enabled.One caveat of the cancelable promise-like generator object is some implicit callback promise handling does not work as expected. In these situations, the returned object is awaited on directly to trigger running the underlying generator.