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

Method sendMessage_

src/web-worker/amp-worker.js:180–197  ·  view source on GitHub ↗

* Sends a method invocation request to the worker and returns a Promise. * @param {string} method * @param {!Array} args * @param {Window=} opt_localWin * @return {!Promise} * @private * @restricted

(method, args, opt_localWin)

Source from the content-addressed store, hash-verified

178 * @restricted
179 */
180 sendMessage_(method, args, opt_localWin) {
181 return this.fetchPromise_.then(() => {
182 return new Promise((resolve, reject) => {
183 const id = this.counter_++;
184 this.messages_[id] = {method, resolve, reject};
185
186 const scope = this.idForWindow_(opt_localWin || this.win_);
187
188 const message = /** @type {ToWorkerMessageDef} */ ({
189 method,
190 args,
191 scope,
192 id,
193 });
194 this.worker_./*OK*/ postMessage(message);
195 });
196 });
197 }
198
199 /**
200 * Receives the result of a method invocation from the worker and resolves

Callers 1

invokeWebWorkerFunction · 0.45

Calls 3

idForWindow_Method · 0.95
thenMethod · 0.45
postMessageMethod · 0.45

Tested by

no test coverage detected