refactor: handle msg in parallel form

This commit is contained in:
Wesley F. Young 2024-09-08 09:58:52 +08:00
parent 0e67ec1a6d
commit b109414193

View File

@ -131,13 +131,22 @@ export class NapCatEventChannel extends
private initMsgListener() { private initMsgListener() {
const msgListener = new NodeIKernelMsgListener(); const msgListener = new NodeIKernelMsgListener();
msgListener.onRecvMsg = async msgList => { msgListener.onRecvMsg = msgList => {
for (const msg of msgList) { Promise.allSettled(
if (msg.senderUin !== this.core.selfInfo.uin) { msgList.filter(msg => msg.senderUin !== this.core.selfInfo.uin)
const handled = await this.parseRawMsgToEventAndEmit(msg); .map(msg => {
this.parseRawMsgToEventAndEmit(msg)
.then(handled => {
if (!handled) this.emit('message/receive', msg); if (!handled) this.emit('message/receive', msg);
});
}),
).then(callRes => {
callRes.forEach(res => {
if (res.status === 'rejected') {
this.core.context.logger.logError('处理消息失败', res.reason);
} }
} });
});
}; };
const msgIdSentCache = new LRUCache<string, boolean>(100); const msgIdSentCache = new LRUCache<string, boolean>(100);