UNPKG

@microsoft/compose-language-service

Version:
26 lines 1.19 kB
/*!-------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------*/ const activeDebounces = {}; export 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), }; } //# sourceMappingURL=debounce.js.map