Path: blob/main/extensions/copilot/src/extension/inlineEdits/common/delay.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/456export class DelaySession {7private extraDebounce = 0;89constructor(10private baseDebounceTime: number,11private expectedTotalTime: number | undefined,12private readonly providerInvocationTime: number = Date.now(),13) {14}1516public setExtraDebounce(extraDebounce: number): void {17this.extraDebounce = extraDebounce;18}1920public setBaseDebounceTime(baseDebounceTime: number): void {21this.baseDebounceTime = baseDebounceTime;22}2324public setExpectedTotalTime(expectedTotalTime: number): void {25this.expectedTotalTime = expectedTotalTime;26}2728getDebounceTime() {29const expectedDebounceTime = this.expectedTotalTime === undefined30? this.baseDebounceTime31: Math.min(this.baseDebounceTime, this.expectedTotalTime);3233const expectedDebounceTimeWithExtras = expectedDebounceTime + this.extraDebounce;3435const timeAlreadySpent = Date.now() - this.providerInvocationTime;36const actualDebounceTime = Math.max(0, expectedDebounceTimeWithExtras - timeAlreadySpent);3738return actualDebounceTime;39}4041getArtificialDelay() {42if (this.expectedTotalTime === undefined) {43return 0;44}4546const timeAlreadySpent = Date.now() - this.providerInvocationTime;47const delay = Math.max(0, this.expectedTotalTime - timeAlreadySpent);48return delay;49}50}515253