import * as LRUCache from "lru-cache" ; import * as vscode from "vscode" ; export const lruCache = new LRUCache < vscode . Uri , MovingAverage > ( 32 ) ; export class MovingAverage { private _n : number = 1 ; private _val : number = 0 ; public update ( value ) { this . _val = this . _val + ( value - this . _val ) / this . _n ; this . _n += 1 ; return this ; } public get value ( ) : number { return this . _val ; } } export function getRequestDelay ( uri ) { const avg = lruCache . get ( uri ) ; if ( ! avg ) { return 350 ; } return Math . max ( 350 , Math . floor ( 1.3 * avg . value ) ) ; }