Refactor event handling to use async/await across adapters
Build Action / Build-LiteLoader (push) Canceled after 0s
Build Action / Build-Shell (push) Canceled after 0s
Build Release / check-version (push) Canceled after 0s
Build Release / Build-LiteLoader (push) Canceled after 0s
Build Release / Build-Shell (push) Canceled after 0s
Build Release / release-napcat (push) Canceled after 0s
Build Release / build-docker (push) Canceled after 0s
Build Action / Build-LiteLoader (push) Canceled after 0s
Build Action / Build-Shell (push) Canceled after 0s
Build Release / check-version (push) Canceled after 0s
Build Release / Build-LiteLoader (push) Canceled after 0s
Build Release / Build-Shell (push) Canceled after 0s
Build Release / release-napcat (push) Canceled after 0s
Build Release / build-docker (push) Canceled after 0s
Updated all network adapters' onEvent methods to be asynchronous and return Promises, ensuring consistent async event emission and handling. Adjusted related methods and event emission logic to properly await asynchronous operations, improving reliability for streaming, plugin, HTTP, and WebSocket event flows. Also improved error handling and messaging in stream and WebSocket actions.
This commit is contained in:
1 parent
a36ae315b0
commit
42d50014a1
11 files changed
+89
-46
No files matched your search
@@ -87,7 +87,7 @@ export class DownloadFileStream extends OneBotAction<Payload, StreamPacket<Downl
|
||||
const totalSize = fileSize || stats.size;
|
||||
|
||||
// 发送文件信息
|
||||
req.send({
|
||||
await req.send({
|
||||
type: StreamStatus.Stream,
|
||||
data_type: 'file_info',
|
||||
file_name: fileName,
|
||||
@@ -104,7 +104,7 @@ export class DownloadFileStream extends OneBotAction<Payload, StreamPacket<Downl
|
||||
const base64Chunk = chunk.toString('base64');
|
||||
bytesRead += chunk.length;
|
||||
|
||||
req.send({
|
||||
await req.send({
|
||||
type: StreamStatus.Stream,
|
||||
data_type: 'file_chunk',
|
||||
index: chunkIndex,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
import { StreamPacket, StreamStatus } from './StreamBasic';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
|
||||
error: Type.Optional(Type.Boolean({ default: false }))
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
@@ -17,13 +17,16 @@ export class TestDownloadStream extends OneBotAction<Payload, StreamPacket<{ dat
|
||||
|
||||
async _handle(_payload: Payload, _adaptername: string, _config: NetworkAdapterConfig, req: OneBotRequestToolkit) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
req.send({ type: StreamStatus.Stream, data: `这是第 ${i + 1} 片流数据`, data_type: 'data_chunk' });
|
||||
await req.send({ type: StreamStatus.Stream, data: `Index-> ${i + 1}`, data_type: 'data_chunk' });
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
}
|
||||
if( _payload.error ){
|
||||
throw new Error('This is a test error');
|
||||
}
|
||||
return {
|
||||
type: StreamStatus.Response,
|
||||
data_type: 'data_complete',
|
||||
data: '流传输完成'
|
||||
data: 'Stream transmission complete'
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user