Skip to content

Fix race condition when resolving performanceTiming.loadEventEnd#22812

Merged
zhouyx merged 4 commits intoampproject:masterfrom
zhouyx:unload-event
Jun 13, 2019
Merged

Fix race condition when resolving performanceTiming.loadEventEnd#22812
zhouyx merged 4 commits intoampproject:masterfrom
zhouyx:unload-event

Conversation

@zhouyx
Copy link
Copy Markdown
Contributor

@zhouyx zhouyx commented Jun 12, 2019

No description provided.

@zhouyx zhouyx requested a review from lannka June 12, 2019 21:58
export function getTimingDataAsync(win, startEvent, endEvent) {
return loadPromise(win).then(() => {
const deferred = new Deferred();
loadPromise(win).then(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would the following work?

loadPromise(win)
    .then(timer.promise(1))
    .then(...);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's should work, as long as there's a setTimeout call involved. But do you think it's worth retrieving the Timer service here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yep, the whole point of timer service is to share code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BTW: I found a delayAfterDeferringToEventLoop method from the lightbox-gallery component and few use case of timer.promise(). May worth introducing a global helper method for this. But I'll stick to timer.promise here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Contributor

@lannka lannka left a comment

Choose a reason for hiding this comment

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

any idea for a test? would it be easy to add an integration test? (check the value is never 0)

@zhouyx
Copy link
Copy Markdown
Contributor Author

zhouyx commented Jun 12, 2019

I couldn't reproduce the same race condition with our integration test fixture. Let me know if you still feel it's worth adding that.

@lannka
Copy link
Copy Markdown
Contributor

lannka commented Jun 12, 2019

Since you already have it, let's get it in. I think there is still value for it.

@zhouyx
Copy link
Copy Markdown
Contributor Author

zhouyx commented Jun 13, 2019

integration test added

@lannka
Copy link
Copy Markdown
Contributor

lannka commented Jun 13, 2019

Thanks for the fix!

@zhouyx zhouyx merged commit a31a1bf into ampproject:master Jun 13, 2019
@zhouyx zhouyx deleted the unload-event branch June 13, 2019 17:51
lannka added a commit to lannka/amphtml that referenced this pull request Jun 27, 2019
lannka added a commit to lannka/amphtml that referenced this pull request Jun 27, 2019
This was referenced Jun 27, 2019
lannka added a commit that referenced this pull request Jun 27, 2019
* Revert #22812

* Revert #22812
sparhami pushed a commit that referenced this pull request Jun 27, 2019
* Revert #22812

* Revert #22812
sparhami pushed a commit that referenced this pull request Jun 27, 2019
* Revert #22812

* Revert #22812
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 this pull request may close these issues.

3 participants