1. 修改了Serein.Library中的ObjectPool工具类,提供了对象归还的默认处理方法(通过构造方法指定Action<T>委托)

2. 不再显式调用流程上下文的Reset()方法,而改为通过对象池调用
3. 同样的,对于同样使用了ObjectPool管理上下文的Serein.Proto.WebSocket项目而言,也进行了同2.一样的修改
This commit is contained in:
fengjiayi
2025-08-23 16:19:30 +08:00
parent 5656619a3b
commit 819320f355
8 changed files with 47 additions and 49 deletions

View File

@@ -197,7 +197,6 @@ namespace Serein.NodeFlow.Services
var context = pool.Allocate();
var instance = ioc.Get(md.ActingInstanceType);
await dd.InvokeAsync(instance, [context]);
context.Reset();
pool.Free(context);
}
ioc.Build(); // 绑定初始化时注册的类型
@@ -225,7 +224,6 @@ namespace Serein.NodeFlow.Services
var context = pool.Allocate();
var instance = ioc.Get(md.ActingInstanceType);
await dd.InvokeAsync(instance, [context]);
context.Reset();
pool.Free(context);
}
ioc.Build(); // 绑定初始化时注册的类型
@@ -255,7 +253,6 @@ namespace Serein.NodeFlow.Services
var context = pool.Allocate();
var instance = ioc.Get(md.ActingInstanceType);
await dd.InvokeAsync(instance, [context]);
context.Reset();
pool.Free(context);
}
@@ -304,7 +301,6 @@ namespace Serein.NodeFlow.Services
var token = WorkOptions.CancellationTokenSource.Token;
var context = pool.Allocate();
await startNode.StartFlowAsync(context, token);
context.Reset();
pool.Free(context);
return;
}
@@ -330,7 +326,6 @@ namespace Serein.NodeFlow.Services
var result = await startNode.StartFlowAsync(context, WorkOptions.CancellationTokenSource.Token); // 开始运行时从选定节点开始运行
checkpoints["执行流程"] = sw.Elapsed;
context.Reset();
pool.Free(context);
checkpoints["释放Context"] = sw.Elapsed;
@@ -437,8 +432,6 @@ namespace Serein.NodeFlow.Services
}
finally
{
context.Reset();
pool.Free(context);
}
}