UNPKG

greybel-languageserver-core

Version:
53 lines 1.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentScheduler = exports.PROCESSING_TIMEOUT = void 0; const events_1 = __importDefault(require("events")); exports.PROCESSING_TIMEOUT = 50; class DocumentScheduler extends events_1.default { constructor(processingTimeout = exports.PROCESSING_TIMEOUT) { super(); this._timer = null; this.scheduledItems = new Map(); this.tickRef = this.tick.bind(this); this.processingTimeout = processingTimeout; } tick() { if (this.scheduledItems.size === 0) { this._timer = null; return; } const currentTime = Date.now(); this.scheduledItems.forEach((item, uri) => { if (currentTime - item.createdAt > this.processingTimeout) { this.emit('process', item.document); this.scheduledItems.delete(uri); } }); this._timer = setTimeout(this.tickRef, 0); } schedule(document) { const fileUri = document.uri; if (this.scheduledItems.has(fileUri)) { return false; } this.scheduledItems.set(fileUri, { document, createdAt: Date.now() }); if (this._timer === null) { this._timer = setTimeout(this.tickRef, 0); } return true; } isScheduled(document) { return this.scheduledItems.has(document.uri); } cancel(document) { return this.scheduledItems.delete(document.uri); } } exports.DocumentScheduler = DocumentScheduler; //# sourceMappingURL=document-scheduler.js.map