Skip to content

added method to cancel screen waitFor #242

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

Closed

Conversation

afzaalahmad
Copy link

It adds a method which will use EventEmitter class to cancel respective screen.waitFor on the basis of templateImageFileName.

@@ -117,6 +122,12 @@ export class Screen {

return new Promise<Region>(async (resolve, reject) => {
try {
const onCancel = (cancelTemplateImageFileName: string) => {
if (templateImageFilename === cancelTemplateImageFileName) {
reject(`Cancelled searching for ${cancelTemplateImageFileName}`);
Copy link
Author

Choose a reason for hiding this comment

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

@s1hofmann @svettwer Not sure, that whether we should reject or resolve it here?

Copy link
Member

@s1hofmann s1hofmann left a comment

Choose a reason for hiding this comment

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

Hi @afzaalahmad 👋

I just took a look at your PR but I have to admit that it doesn't actually adress the problem you described.

Your PR only addresses Screen#find and reject early on a cancel event.
However, Screen#waitFor would just recognise this early rejection as a single failure and simply retry.
The actual thing we want to cancel is the timeout.

@@ -131,8 +142,10 @@ export class Screen {
matchResult.location.height
)
if (this.config.autoHighlight) {
this.eventEmitter.removeListener('cancelWaitFor', onCancel);
Copy link
Member

Choose a reason for hiding this comment

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

Listeners are not removed on error paths and thus pile up over time

resolve(this.highlight(resultRegion));
} else {
this.eventEmitter.removeListener('cancelWaitFor', onCancel);
Copy link
Member

Choose a reason for hiding this comment

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

Listeners are not removed on error paths and thus pile up over time

/**
* @param templateImageFilename Filename of the template image to cancel waitFor of, relative to {@link Screen.config.resourceDirectory}
*/
public async cancelWaitFor(
Copy link
Member

Choose a reason for hiding this comment

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

To be honest, I don't think having explicit methods to cancel actions is something I want.
Having an explicit cancel method for each action with timeouts sound like too much overhead for me.

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