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

PresentationRequest.getAvailability() could always return a new Promise #507

Closed
markafoltz opened this issue Sep 30, 2022 · 3 comments · Fixed by #525
Closed

PresentationRequest.getAvailability() could always return a new Promise #507

markafoltz opened this issue Sep 30, 2022 · 3 comments · Fixed by #525
Assignees
Labels

Comments

@markafoltz
Copy link
Contributor

The steps for getAvailability() have an optimization (?) to return (sometimes) a pre-existing Promise from a previous call to getAvailability().

However this isn't consistent with other specs that always return a new Promise when starting an asynchronous action on another device:

Those are a few examples pulled by skimming other specs, there are likely more.

The Promise-caching also produces some implementation complexity because the browser must sometimes store the Promise like a property of the request, and sometimes allocate a new object and pass it directly to script.

It would be simpler to implement, and more consistent with other specs, to always return a new Promise here.

@markafoltz
Copy link
Contributor Author

This Blink code review has some additional conversation about why this is simpler to implement (at least in Blink.) The CL was abandoned until the spec could be updated with this behavior.

@markafoltz
Copy link
Contributor Author

I reviewed the discussion in the TAG guidance and now believe that returning a new Promise is the right thing to do for two reasons.

  1. Because browsers can become able or unable to monitor the list of presentation displays in the background, the getAvailability() method is a "state transition" case and not a "one time asynchronous function" case in the TAG guidance.

  2. With the current algorithm, an app will have no way to monitor availability if the browser becomes able to monitor presentation displays (when it could not before) because the previously-rejected Promise will always be returned. The only way would be to create a new but identical PresentationRequest, which is not very intuitive.

To implement the full "state transition" guidance and conditionally return existing Promises would add significant complexity to the spec and implementations, because the browser would need to track all of the reasons why monitoring was possible (or not) continuously, and signal the API to behave accordingly on state transitions. In Chrome, there are at least 5-6 reasons I can think of, and some that Chrome can't even know about until it tries to query for compatible devices. I don't support adding this requirement to implementations.

@anssiko
Copy link
Member

anssiko commented Oct 7, 2024

Thanks for looking into the TAG guidance and documenting the rationale here. I agree with your assessment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants