From 6dc958dfb38eabfeba02ab26eef71a2612b6984a Mon Sep 17 00:00:00 2001 From: blacktunes Date: Sun, 16 Jan 2022 16:12:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=AA=E5=AE=8C=E6=88=90=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=B7=BB=E5=8A=A0API=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Connect/Connect.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Connect/Connect.ts b/src/Connect/Connect.ts index c21584a..512ed23 100644 --- a/src/Connect/Connect.ts +++ b/src/Connect/Connect.ts @@ -165,7 +165,7 @@ export class Connect { } if (data.echo) { if (this.APIList.has(data.echo)) { - this.APIList.get(data.echo)(data) + this.APIList.get(data.echo).fn(data) } } } @@ -258,7 +258,7 @@ export class Connect { return this } - private getRes = (id: number) => { + private getRes = (id: number, apiName: string, params: any = {}) => { return new Promise(resolve => { // let timer = setTimeout(() => { // resolve({ @@ -267,15 +267,21 @@ export class Connect { // msg: '请求超时' // }) // }, this.timeout) - this.APIList.set(id, (data: any) => { - resolve({ - data: data.data, - retcode: data.retcode, - status: data.status - }) - this.APIList.delete(id) - // clearTimeout(timer) - // timer = null + this.APIList.set(id, { + info: { + apiName, + params + }, + fn: (data: any) => { + resolve({ + data: data.data, + retcode: data.retcode, + status: data.status + }) + this.APIList.delete(id) + // clearTimeout(timer) + // timer = null + } }) }) } @@ -287,7 +293,7 @@ export class Connect { return this.messageEventList.message.length } - private APIList = new Map() + private APIList = new Map() /** * 获取队列中未完成的消息数量 */ @@ -307,7 +313,7 @@ export class Connect { params, echo: id })) - const res = await this.getRes(id) + const res = await this.getRes(id, apiName, params) if (errorLog && res.status !== 'ok') { PrintLog.logError(`${white(apiName)} 调用失败 recode: ${white(res.retcode.toString())} msg: ${white(res.msg || '未知错误')}`, 'WS') }