@microsoft/compose-language-service
Version:
Language service for Docker Compose documents
30 lines • 1.31 kB
JavaScript
;
/*!--------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.debounce = void 0;
const activeDebounces = {};
function debounce(delay, id, callback, thisArg) {
const idString = `${id.uri}/${id.callId}`;
// If there's an existing call queued up, wipe it out (can't simply refresh as the inputs to the callback may be different)
if (activeDebounces[idString]) {
activeDebounces[idString].dispose();
delete activeDebounces[idString];
}
// Schedule the callback
const timeout = setTimeout(() => {
// Clear the callback since we're about to fire it
activeDebounces[idString].dispose();
delete activeDebounces[idString];
// Fire it
void callback.call(thisArg);
}, delay);
// Keep track of the active debounce
activeDebounces[idString] = {
dispose: () => clearTimeout(timeout),
};
}
exports.debounce = debounce;
//# sourceMappingURL=debounce.js.map