-
Notifications
You must be signed in to change notification settings - Fork 53
Don't require action within a Promise reaction microtask. #570
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jan-ivar. I've left a bunch of suggestions for @martinthomson to review, and you're welcome to apply any that you agree with or make other changes in response, but we can also take it from here.
Co-authored-by: Jeffrey Yasskin <[email protected]>
|
||
<p>If an algorithm requires that callback functions respond | ||
synchronously (e.g. to take or veto some action), then that is a | ||
synchronous API, and should not be modelled with a promise. Instead, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
synchronous API, and should not be modelled with a promise. Instead, | |
synchronous API, and should not be modeled with a Promise. Instead, |
you may not require action within | ||
a fixed number of microtasks.</p> | ||
|
||
<p>This protects promise composition: patterns like <code>await</code>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<p>This protects promise composition: patterns like <code>await</code>, | |
<p>This protects Promise composition: patterns like <code>await</code>, |
If developer-supplied code needs to be able to call <code>event.{{Event/preventDefault()}}</code> | ||
or choose a response object with | ||
<code>fetchEvent.{{FetchEvent/respondWith()}}</code>, | ||
it needs to be a callback rather than a reaction passed to <code>Promise.{{Promise/then()}}</code>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a good example or a bad one?
A non-event example is the <code>captureController.{{CaptureController/setFocusBehavior()}}</code> | ||
method to push a window the user has chosen to screen-capture, to | ||
the front. Applications can decide this based on the window chosen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A non-event example is the <code>captureController.{{CaptureController/setFocusBehavior()}}</code> | |
method to push a window the user has chosen to screen-capture, to | |
the front. Applications can decide this based on the window chosen. | |
A non-event example is the <code>captureController.{{CaptureController/setFocusBehavior()}}</code> | |
method, which pushes a window the user has chosen to screen-capture to | |
the front. Applications can decide this based on the window chosen. |
A non-event example is the <code>captureController.{{CaptureController/setFocusBehavior()}}</code> | ||
method to push a window the user has chosen to screen-capture, to | ||
the front. Applications can decide this based on the window chosen. | ||
But any delay risks click-jacking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But any delay risks click-jacking. | |
The challenge is that allowing delay creates an opportunity for click-jacking attacks from sites. |
A link defining click-jacking would be helpful.
But any delay risks click-jacking. | ||
|
||
Instead of requiring the method be called synchronously on the | ||
reaction microtask of the promise from `getDisplayMedia()`, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reaction microtask of the promise from `getDisplayMedia()`, the | |
reaction microtask of the promise from `getDisplayMedia()`, the |
A link to getDisplayMedia()
would also be helpful.
<h4 id="sync-callbacks">When to use callback functions instead</h4> | ||
|
||
<p>If an algorithm requires that callback functions respond | ||
synchronously (e.g. to take or veto some action), then that is a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
synchronously (e.g. to take or veto some action), then that is a | |
synchronously (e.g., to take or veto some action), then that is a |
I'm not sure about our conventions here; this is the one that I've been taught to use.
... checks ...
damn. Well.
Fixes #342.
Preview (#sync-callbacks) (#promises-and-reacti…) | Diff