MCPcopy Create free account
hub / github.com/ampproject/amphtml / awaitEvent

Function awaitEvent

testing/iframe.js:106–121  ·  view source on GitHub ↗
(eventName, count)

Source from the content-addressed store, hash-verified

104 // Function that returns a promise for when the given event fired at
105 // least count times.
106 const awaitEvent = (eventName, count) => {
107 if (!(eventName in events)) {
108 throw new Error('Unknown custom event ' + eventName);
109 }
110 return new Promise(function (resolve) {
111 if (events[eventName] >= count) {
112 resolve();
113 } else {
114 win.addEventListener(eventName, () => {
115 if (events[eventName] == count) {
116 resolve();
117 }
118 });
119 }
120 });
121 };
122 // Record firing of custom events.
123 for (const name in events) {
124 win.addEventListener(name, () => {

Callers

nothing calls this directly

Calls 2

resolveFunction · 0.50
addEventListenerMethod · 0.45

Tested by

no test coverage detected