MCPcopy
hub / github.com/ampproject/amphtml / getMeasuredResources

Function getMeasuredResources

src/ini-load.js:153–182  ·  view source on GitHub ↗
(ampdoc, hostWin, filterFn)

Source from the content-addressed store, hash-verified

151 * @return {!Promise<!Array<!./service/resource.Resource>>}
152 */
153export function getMeasuredResources(ampdoc, hostWin, filterFn) {
154 // First, wait for the `ready-scan` signal. Waiting for each element
155 // individually is too expensive and `ready-scan` will cover most of
156 // the initially parsed elements.
157 return ampdoc
158 .signals()
159 .whenSignal(READY_SCAN_SIGNAL)
160 .then(() => {
161 // Second, wait for any left-over elements to complete measuring.
162 const measurePromiseArray = [];
163 const resources = Services.resourcesForDoc(ampdoc);
164 resources.get().forEach((r) => {
165 if (!r.hasBeenMeasured() && r.hostWin == hostWin && !r.hasOwner()) {
166 measurePromiseArray.push(r.ensureMeasured());
167 }
168 });
169 return Promise.all(measurePromiseArray);
170 })
171 .then(() => {
172 const resources = Services.resourcesForDoc(ampdoc);
173 return resources.get().filter((r) => {
174 return (
175 r.hostWin == hostWin &&
176 !r.hasOwner() &&
177 r.hasBeenMeasured() &&
178 filterFn(r)
179 );
180 });
181 });
182}

Callers 2

groupAmpAdsByTypeFunction · 0.90

Calls 10

whenSignalMethod · 0.80
hasBeenMeasuredMethod · 0.80
hasOwnerMethod · 0.80
ensureMeasuredMethod · 0.80
thenMethod · 0.45
signalsMethod · 0.45
forEachMethod · 0.45
getMethod · 0.45
pushMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected