Skip to content

Commit

Permalink
feat: 未完成消息添加API信息
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktunes committed Jan 16, 2022
1 parent 80e0117 commit 6dc958d
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/Connect/Connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ export class Connect {
return this
}

private getRes = (id: number) => {
private getRes = (id: number, apiName: string, params: any = {}) => {
return new Promise<ApiRes>(resolve => {
// let timer = setTimeout(() => {
// resolve({
Expand All @@ -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
}
})
})
}
Expand All @@ -287,7 +293,7 @@ export class Connect {
return this.messageEventList.message.length
}

private APIList = new Map<number, Function>()
private APIList = new Map<number, { fn: Function, info: any }>()
/**
* 获取队列中未完成的消息数量
*/
Expand All @@ -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')
}
Expand Down

0 comments on commit 6dc958d

Please sign in to comment.