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

Function computeInMasterFrame

3p/3p.js:172–196  ·  view source on GitHub ↗
(global, taskId, work, cb)

Source from the content-addressed store, hash-verified

170 * done. The first argument is the result.
171 */
172export function computeInMasterFrame(global, taskId, work, cb) {
173 const {master} = global.context;
174 let tasks = master.__ampMasterTasks;
175 if (!tasks) {
176 tasks = master.__ampMasterTasks = {};
177 }
178 let cbs = tasks[taskId];
179 if (!tasks[taskId]) {
180 cbs = tasks[taskId] = [];
181 }
182 cbs.push(cb);
183 if (!global.context.isMaster) {
184 return; // Only do work in master.
185 }
186 work((result) => {
187 for (let i = 0; i < cbs.length; i++) {
188 cbs[i].call(null, result);
189 }
190 tasks[taskId] = {
191 push(cb) {
192 cb(result);
193 },
194 };
195 });
196}
197
198/**
199 * Validates given data. Throws an exception if the data does not

Callers 10

computeInMasterFrameMethod · 0.90
test-3p.jsFile · 0.90
swoopFunction · 0.90
kargoFunction · 0.90
loadHBTagFunction · 0.90
sspFunction · 0.90
yieldproFunction · 0.90
springAdsFunction · 0.90
imediaFunction · 0.90
requestCodesFunction · 0.90

Calls 2

workFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected