MCPcopy Index your code
hub / github.com/nodejs/node / createDynamicPriorityPollingWatchFile

Function createDynamicPriorityPollingWatchFile

test/fixtures/snapshot/typescript.js:6252–6359  ·  view source on GitHub ↗
(host)

Source from the content-addressed store, hash-verified

6250 }
6251 /* @internal */
6252 function createDynamicPriorityPollingWatchFile(host) {
6253 var watchedFiles = [];
6254 var changedFilesInLastPoll = [];
6255 var lowPollingIntervalQueue = createPollingIntervalQueue(PollingInterval.Low);
6256 var mediumPollingIntervalQueue = createPollingIntervalQueue(PollingInterval.Medium);
6257 var highPollingIntervalQueue = createPollingIntervalQueue(PollingInterval.High);
6258 return watchFile;
6259 function watchFile(fileName, callback, defaultPollingInterval) {
6260 var file = {
6261 fileName: fileName,
6262 callback: callback,
6263 unchangedPolls: 0,
6264 mtime: getModifiedTime(host, fileName)
6265 };
6266 watchedFiles.push(file);
6267 addToPollingIntervalQueue(file, defaultPollingInterval);
6268 return {
6269 close: function () {
6270 file.isClosed = true;
6271 // Remove from watchedFiles
6272 ts.unorderedRemoveItem(watchedFiles, file);
6273 // Do not update polling interval queue since that will happen as part of polling
6274 }
6275 };
6276 }
6277 function createPollingIntervalQueue(pollingInterval) {
6278 var queue = [];
6279 queue.pollingInterval = pollingInterval;
6280 queue.pollIndex = 0;
6281 queue.pollScheduled = false;
6282 return queue;
6283 }
6284 function pollPollingIntervalQueue(queue) {
6285 queue.pollIndex = pollQueue(queue, queue.pollingInterval, queue.pollIndex, pollingChunkSize[queue.pollingInterval]);
6286 // Set the next polling index and timeout
6287 if (queue.length) {
6288 scheduleNextPoll(queue.pollingInterval);
6289 }
6290 else {
6291 ts.Debug.assert(queue.pollIndex === 0);
6292 queue.pollScheduled = false;
6293 }
6294 }
6295 function pollLowPollingIntervalQueue(queue) {
6296 // Always poll complete list of changedFilesInLastPoll
6297 pollQueue(changedFilesInLastPoll, PollingInterval.Low, /*pollIndex*/ 0, changedFilesInLastPoll.length);
6298 // Finally do the actual polling of the queue
6299 pollPollingIntervalQueue(queue);
6300 // Schedule poll if there are files in changedFilesInLastPoll but no files in the actual queue
6301 // as pollPollingIntervalQueue wont schedule for next poll
6302 if (!queue.pollScheduled && changedFilesInLastPoll.length) {
6303 scheduleNextPoll(PollingInterval.Low);
6304 }
6305 }
6306 function pollQueue(queue, pollingInterval, pollIndex, chunkSize) {
6307 return pollWatchedFileQueue(host, queue, pollIndex, chunkSize, onWatchFileStat);
6308 function onWatchFileStat(watchedFile, pollIndex, fileChanged) {
6309 if (fileChanged) {

Callers 1

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…