diff --git a/src/decorators/cfg.ts b/src/decorators/cfg.ts index 63c1b62..5cf5e02 100644 --- a/src/decorators/cfg.ts +++ b/src/decorators/cfg.ts @@ -2,7 +2,11 @@ import {singleton} from "../common/Singleton"; import {GameEnv} from "../cfg/GameEnv"; const baseCfg = new GameEnv(); - +const delayRun = function (max: number, min?: number) { + min = min || 0; + let milliseconds = (Math.random() * (max - min) + min) * 1000 | 0; + return new Promise(resolve => setTimeout(resolve, milliseconds)); +} /** * 根据配置项延迟执行的修饰器 * @param type GameEnv中的字段名 @@ -12,11 +16,7 @@ export function wait(type: string) { propertyKey: string, descriptor: PropertyDescriptor) => { const method = descriptor.value; - let delayRun = function (max: number, min?: number) { - min = min || 0; - let milliseconds = (Math.random() * (max - min) + min) * 1000 | 0; - return new Promise(resolve => setTimeout(resolve, milliseconds)); - } + descriptor.value = function (...args: any[]) { // @ts-ignore let time = baseCfg[type] as number; @@ -26,8 +26,9 @@ export function wait(type: string) { let minTime = minDelay / 100 * time; delayRun(maxTime, minTime) .then(() => { + return method!.apply(this, args); }) - .finally(() => { + .catch(err => { return method!.apply(this, args); }) @@ -44,11 +45,6 @@ export function delay(num: number) { propertyKey: string, descriptor: PropertyDescriptor) => { const method = descriptor.value; - let delayRun = function (max: number, min?: number) { - min = min || 0; - let milliseconds = (Math.random() * (max - min) + min) * 1000 | 0; - return new Promise(resolve => setTimeout(resolve, milliseconds)); - } descriptor.value = function (...args: any[]) { delayRun(num, 0) .then(() => {