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

Method whenSignal

src/core/data-structures/signals.js:52–74  ·  view source on GitHub ↗

* Returns the promise that's resolved when the signal is triggered. The * resolved value is the time of the signal. * @param {string} name * @return {Promise }

(name)

Source from the content-addressed store, hash-verified

50 * @return {Promise<TimestampDef>}
51 */
52 whenSignal(name) {
53 let promiseStruct = this.promiseMap_?.[name];
54 if (!promiseStruct) {
55 const result = this.map_[name];
56 if (result != null) {
57 // Immediately resolve signal.
58 const promise =
59 typeof result == 'number'
60 ? Promise.resolve(result)
61 : Promise.reject(result);
62 promiseStruct = {promise};
63 } else {
64 // Allocate the promise/resolver for when the signal arrives in the
65 // future.
66 promiseStruct = new Deferred();
67 }
68 if (!this.promiseMap_) {
69 this.promiseMap_ = map();
70 }
71 this.promiseMap_[name] = promiseStruct;
72 }
73 return promiseStruct.promise;
74 }
75
76 /**
77 * Triggers the signal with the specified name on the element. The time is

Callers 15

waitForCarouselLayoutFunction · 0.80
getVideoPlayerFunction · 0.80
test-runtime.jsFile · 0.80
test-signals.jsFile · 0.80
whenUpgradedMethod · 0.80
whenBuiltMethod · 0.80
buildMethod · 0.80
mountMethod · 0.80
whenMountedMethod · 0.80
whenLoadedMethod · 0.80
createImpl_Method · 0.80
whenContentIniLoadInObFunction · 0.80

Calls 2

mapFunction · 0.90
resolveMethod · 0.80

Tested by

no test coverage detected