source-queue.js (1097B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 const { throttle } = require("resource://devtools/shared/throttle.js"); 6 7 // This SourceQueue module is now only used for source mapped sources 8 let newOriginalQueuedSources; 9 let queuedOriginalSources; 10 let currentWork; 11 12 async function dispatchNewSources() { 13 const sources = queuedOriginalSources; 14 if (!sources.length) { 15 return; 16 } 17 queuedOriginalSources = []; 18 currentWork = await newOriginalQueuedSources(sources); 19 } 20 21 const queue = throttle(dispatchNewSources, 100); 22 23 export default { 24 initialize: actions => { 25 newOriginalQueuedSources = actions.newOriginalSources; 26 queuedOriginalSources = []; 27 }, 28 queueOriginalSources: sources => { 29 if (sources.length) { 30 queuedOriginalSources.push(...sources); 31 queue(); 32 } 33 }, 34 35 flush: () => Promise.all([queue.flush(), currentWork]), 36 clear: () => { 37 queuedOriginalSources = []; 38 queue.cancel(); 39 }, 40 };