Telegram Web K with changes to work inside I2P https://web.telegram.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

36 lines
808 B

/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
import ctx from "../environment/ctx";
type CacheFunction = (...args: any[]) => any;
const cache: Map<CacheFunction, {result: any, timeout: number}> = new Map();
Function.prototype.cache = function(thisArg, ...args: any[]) {
let cached = cache.get(this);
if(cached) {
return cached.result;
}
const result = this.apply(thisArg, args as any);
cache.set(this, cached = {
result,
timeout: ctx.setTimeout(() => {
cache.delete(this);
}, 60000)
});
return result;
};
declare global {
interface Function {
cache<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg?: T, ...args: A): R;
}
}
export {};