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

Method timeoutPromise

src/service/timer-impl.js:126–145  ·  view source on GitHub ↗

* Returns a promise that will fail after the specified delay. Optionally, * this method can take opt_racePromise parameter. In this case, the * resulting promise will either fail when the specified delay expires or * will resolve based on the opt_racePromise, whichever happens first. * @

(delay, opt_racePromise, opt_message)

Source from the content-addressed store, hash-verified

124 * @template RESULT
125 */
126 timeoutPromise(delay, opt_racePromise, opt_message) {
127 let timerKey;
128 const delayPromise = new this.win.Promise((_resolve, reject) => {
129 timerKey = this.delay(() => {
130 reject(user().createError(opt_message || 'timeout'));
131 }, delay);
132
133 if (timerKey == -1) {
134 throw new Error('Failed to schedule timer.');
135 }
136 });
137 if (!opt_racePromise) {
138 return delayPromise;
139 }
140 const cancel = () => {
141 this.cancel(timerKey);
142 };
143 opt_racePromise.then(cancel, cancel);
144 return this.win.Promise.race([delayPromise, opt_racePromise]);
145 }
146
147 /**
148 * Returns a promise that resolves after `predicate` returns true.

Callers 15

test-timer.jsFile · 0.80
onMouseMove_Method · 0.80
waitForServicesFunction · 0.80
closeShadowRoot_Method · 0.80
getOrCreateAdCidFunction · 0.80
maybeTrackImpressionFunction · 0.80
isStoryDocumentFunction · 0.80
getMethod · 0.80
fetchCid_Method · 0.80
initMessagingChannel_Method · 0.80
getViewerOriginMethod · 0.80

Calls 4

delayMethod · 0.95
userFunction · 0.90
createErrorMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected