mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
1. 修改了Serein.Library中的ObjectPool工具类,提供了对象归还的默认处理方法(通过构造方法指定Action<T>委托)
2. 不再显式调用流程上下文的Reset()方法,而改为通过对象池调用 3. 同样的,对于同样使用了ObjectPool管理上下文的Serein.Proto.WebSocket项目而言,也进行了同2.一样的修改
This commit is contained in:
@@ -344,7 +344,7 @@ namespace Serein.Proto.WebSocket.Handle
|
||||
return;
|
||||
}
|
||||
// 返回结果
|
||||
var responseData = context.OnReplyMakeData(context, data);
|
||||
var responseData = context.OnReplyMakeData?.Invoke(context, data);
|
||||
if (responseData is null)
|
||||
{
|
||||
context.TriggerExceptionTracking(new ArgumentNullException($"处理回调函数 OnReplyMakeData 返回 null"));
|
||||
|
||||
@@ -325,14 +325,22 @@ namespace Serein.Proto.WebSocket
|
||||
{
|
||||
await SocketExtension.SendAsync(webSocket, text); // 回复客户端,处理方法中入参如果需要发送消息委托,则将该回调方法作为委托参数传入
|
||||
}
|
||||
/*
|
||||
ObjectPool<WebSocketMsgContext> contextPool = new ObjectPool<WebSocketMsgContext>(() =>
|
||||
{
|
||||
return new WebSocketMsgContext(sendasync);
|
||||
}, 20);
|
||||
var context = contextPool.Allocate();
|
||||
contextPool.Free(context);
|
||||
*/
|
||||
|
||||
ObjectPool<WebSocketHandleContext> contextPool = new ObjectPool<WebSocketHandleContext>(() =>
|
||||
{
|
||||
var context = new WebSocketHandleContext(sendasync);
|
||||
context.OnExceptionTracking = _onExceptionTracking;
|
||||
context.OnReplyMakeData = _onReplyMakeData;
|
||||
context.OnReply = _onReply;
|
||||
return context;
|
||||
}, context =>
|
||||
{
|
||||
context.MsgRequest = null;
|
||||
context.MsgData = null;
|
||||
context.ErrorMessage = null;
|
||||
context.Model = null;
|
||||
});
|
||||
|
||||
while (webSocket.State == WebSocketState.Open)
|
||||
{
|
||||
var message = await tranTool.WaitMsgAsync(); // 有消息时通知
|
||||
@@ -341,12 +349,10 @@ namespace Serein.Proto.WebSocket
|
||||
Console.WriteLine($"WebSocket 消息解析失败: {message}");
|
||||
continue;
|
||||
}
|
||||
var context = new WebSocketHandleContext(sendasync);
|
||||
var context = contextPool.Allocate();
|
||||
context.MsgRequest = jsonReques;
|
||||
context.OnExceptionTracking = _onExceptionTracking;
|
||||
context.OnReplyMakeData = _onReplyMakeData;
|
||||
context.OnReply = _onReply;
|
||||
await HandleAsync(context); // 处理消息
|
||||
contextPool.Free(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user