mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: fix #1078
This commit is contained in:
3 files changed
+4
-38
No files matched your search
@@ -253,42 +253,6 @@ export function findFileSync(pathname: string, doThrow: boolean | Error = true)
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function retry<Arg extends any[], Ret>(func: (...args: Arg) => Ret, ...args: Arg): Promise<Ret>;
|
||||
export async function retry<Arg extends any[], Ret>(times: number, func: (...args: Arg) => Ret, ...args: Arg): Promise<Ret>;
|
||||
// eslint-disable-next-line consistent-return
|
||||
export async function retry(arg0: number | ((...args: any[]) => any), func: any, ...args: any[]): Promise<any> {
|
||||
let res;
|
||||
if (typeof arg0 !== 'number') {
|
||||
args = [func, ...args];
|
||||
func = arg0;
|
||||
arg0 = 3;
|
||||
}
|
||||
for (let i = 1; i <= arg0; i++) {
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
res = await func(...args);
|
||||
} catch (e) {
|
||||
if (i === arg0) throw e;
|
||||
continue;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
export function CallableInstance(property = '__call__') {
|
||||
let func;
|
||||
if (typeof property === 'function') func = property;
|
||||
else func = this.constructor.prototype[property];
|
||||
const apply = function __call__(...args) { return func.apply(apply, ...args); };
|
||||
Object.setPrototypeOf(apply, this.constructor.prototype);
|
||||
for (const p of Object.getOwnPropertyNames(func)) {
|
||||
Object.defineProperty(apply, p, Object.getOwnPropertyDescriptor(func, p));
|
||||
}
|
||||
return apply;
|
||||
}
|
||||
|
||||
CallableInstance.prototype = Object.create(Function.prototype);
|
||||
|
||||
export const htmlEncode = (str: string) => str.replace(/[&<>'"]/g,
|
||||
(tag: string) => ({
|
||||
'&': '&',
|
||||
|
||||
Reference in new issue
Block a user