-
Notifications
You must be signed in to change notification settings - Fork 59
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
Use task source mechanism to dispatch events instead of firing them synchronously #215
Comments
@tobie @pozdnyakov @anssiko ptal |
That's a great insight. I need to read-up more on ho task sources actually function to be able to make an educated comment here. You might have noted that I have an inline issue on that topic in the spec. I'll link to this instead. |
I think that reflects also the actual implementation in Chromium.. |
That said:
I think that is what the spec is currently doing, no?
Afaik, the task source was brought in (by @anssi) only as a mechanism to deal with mitigation strategies, it can be added differently. As mentioned above, I know little about how it works or the difference between the two. |
With the new information in #215 (comment), the suggestion I made in #81 (comment) is no longer valid. @tobie, I'm fine removing the task source concept from the spec. |
No thanks. I'll fix it as part of #213. |
That's at the discretion of the editor. ;) |
OK, so after discussing this in #whatwg, it seems that whole Update Reading algorithm should happen in a new task, so we avoid updating the shared buffer in the middle of a script being processed, in which case, Once in this task, however, we could continue firing the events directly (as we now do). |
As an internal slot, it can still have side effects on the JS side.
But this is implementation specific, it is not specified by the spec, is it? I don't think it is, tbh. Maybe switching steps 6 and 7 of the "Update latest reading" algorithms would do that. But overall, I think we could replace this whole "reporting flag thing" by simply adding the whole "Update latest reading" in a new task. |
Then it would be bug for the browser that introduces such side effects, internal implementation should not affect specified behavior.
Well, we had consensus that it should be true for event loop turn. If that is not in the spec, maybe we should reflect that agreement, do you want me to make PR for that? 😄
I think tbh :) and we have tests for that that actually work.
As I mentioned in this issue, event queues are overkill for such simple event processing model. |
Unfortunately, I don't remember whether this commit was reviewed by anyone. |
Fwiw, that's a word for word copy of text submitted by @anssiko here: #81 (comment). That said, depending on the context, editing process of specs can be a lot looser than that of code. What's important is for the editor to garner group consensus. It's pretty obvious from the above link that it was the case. I'm not quite sure what point you're trying to make, here nor why you're responding so defensively to my comments. My goal here is to make sure that we have a solid spec. Nothing else. |
I meant that changing it in the middle of an event turn could be observable in JS. Sorry for the confusion.
I'm not sure what you mean. I don't recall discussing this before. Nor should it be a topic of consensus. Having an attribute change value in the middle of an event turn isn't something you want to see on the platform at all. This is not subject to discussion. Would you be confusing this issue with If not, before submitting a PR, could you please enlighten me on how you would solve this besides the step-switching I suggested above?
Well again, I'm not arguing your implementation doesn't do the right thing. I'm saying I don't think the spec guards against this issue, but as I said, this is an area where I don't have a great understanding of how the spec works. The people I talked about this on the #whatwg seemed to imply that we should be calling the whole thing from a task to avoid the
We don't have that now. So I'm not sure what you mean.
Nope. But you seem to know a lot about this stuff, so maybe you can help address my concerns, no?
Yeah, the people I talked to didn't seem to think event queues would be useful here either. They just suggested having a new task for the Update latest reading algorithm. At least that what I understood. |
Sorry if I sounded defensively, I had no such intention. I like facts based, technical approach when decisions are made. So, I'm asking lots of 'why' to understand what were the technical aspects for some decisions that we have in the spec at the moment.
We have same goal, that's why we are trying to help by pushing PR's, reviewing PRs, actively participating in all discussions, implementing spec in browser, etc. |
|
Yeah, that's not the same issue at all. This was about the reading object being immutable. A completely different story. Here we're talking about the shared buffer changing value in the middle of an executing script. |
For reference, here's the log of our conversation on #whatwg: http://logs.glob.uno/?c=freenode%23whatwg#c1029330 |
No problems, sorry, maybe I was also unclear. Shared buffer is internal implementation detail and internal slot, good implementation would treat it this way. External behavior must be same regardless of implementation details. Thus, in chromium, if shared buffer is updated in the middle of the script, it will not be observable on JS side, e.g.,
Was there a time when we had issue just about one thing 😃 ? Rick proposed quite nice set of tests and everyone agreed, issue closed and implemented in chrome according to agreement.
Thanks, you asked on irc about other specs, you might want to check IDB, WebSockets and if I remember correctly MediaStream interface.
We have mixed model :D Sensor is a task source that should add events to the queue, and it should stop (start) queue processing when visibility changes. |
Well, I agree. But good spec works makes sure that it is spec'ed properly.
Yeah, I'm not suggesting your implementation has issues. Just that the spec isn't clear about that and that, according to the thread mentioned above, using a task (on the spec side) is the way to handle this.
Well, it's a concurrency issue, so
Could you point me to where in the spec this is fixed. I fail to see how anything in that PR fixes it (which doesn't mean it's not fixed, just I fail to see it).
😂 😂 😂
Not sure what the consensus about WebSockets is nowadays (but it's a pretty old spec), but I don't think either IDB or MediaStream has a good reputation in terms of being properly spec'ed.
Yeah—I know. The backstory is that I added @anssiko's work in there to meet a deadline, knowing very well we'd have to tackle the task issue heads on at some point. Hence the inline issue on the topic I added later. Technical debt. |
Re technical debt, now that we have a tighter feedback loop with the implementation similar accidents are less likely to happen again. |
Sure, report latest reading updated algorithm and update sensor reading that makes deep copy of latest reading to Sensor.reading, therefore, Sensor.reading is not pointing directly to internal shared buffer (latest reading), thus, modification of latest reading in the middle of script execution would not modify Sensor.reading.
Technical debt is fine, as long as we are taking care of it. Thanks for involving #whatwg and asking for hints! |
Feedback from implementors is great, but that particular issue was completely orthogonal, tbh. |
So definitive feedback from WHATWG folks is roughly to write:
So we can get rid of the custom task queue, but not of task queues altogether. |
For further reference: http://logs.glob.uno/?c=freenode%23whatwg#c1029373, including Anne who says:
|
…d internal slots used in the Sensor interface specification. The refactoring goals are: 1) Stop firing events synchronously. 2) Clean up the internal slots after stop or error. 3) Fix logical errors in the abstract operations. 3) Recompose abstract operations so that duplication of the algorithms steps is removed. 4) Drop the unused abstract operations and internal slots. Fixes w3c#199 Fixes w3c#200 Fixes w3c#201 Fixes w3c#203 Fixes w3c#218 Fixes w3c#215 Fixes w3c#204
…d internal slots used in the Sensor interface specification. The refactoring goals are: - Stop firing events synchronously. - Reset internal slots values after stop. - Fix logical errors in the abstract operations. - Recompose abstract operations so that duplication of the algorithms steps is removed. - Drop the unused abstract operations and internal slots. Fixes w3c#203 Fixes w3c#218 Fixes w3c#215 Fixes w3c#204 Fixes w3c#126 Fixes w3c#243
Short summary:
Sensors are operating in simple Publish & Subscribe model, therefore, queued event processing is not required and over-complicates API and it's implementation.
Detailed explanation:
Event queue is suitable for cases where ordered task processing is needed. For example, networking, databases or APIs that provide sync API and manage async task queue. You can call
write(data);
multiple times and each write is ordered task, if error happens, all pending tasks are removed from queue and'onerror'
event task is put to the queue.Problems with queued task processing:
'onchange'
event would need to carry reading data, otherwise when event queue is processed, event would not be in sync withSensor.|reading|
event.reading != Sensor.reading
, might be confusing for developers.Pros for simple event:
onchange
is synchronized withSensor.reading
Proposed resolution:
The text was updated successfully, but these errors were encountered: