mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-26 15:15:04 +03:00
Optimization and Improvement.
Changed callback from synchronous Action<bool, string> to asynchronous Func<bool, string, Task>
This commit is contained in:
@@ -8,11 +8,11 @@ public class StatisticsSingboxService
|
||||
private readonly Config _config;
|
||||
private bool _exitFlag;
|
||||
private ClientWebSocket? webSocket;
|
||||
private Action<ServerSpeedItem>? _updateFunc;
|
||||
private readonly Func<ServerSpeedItem, Task>? _updateFunc;
|
||||
private string Url => $"ws://{Global.Loopback}:{AppManager.Instance.StatePort2}/traffic";
|
||||
private static readonly string _tag = "StatisticsSingboxService";
|
||||
|
||||
public StatisticsSingboxService(Config config, Action<ServerSpeedItem> updateFunc)
|
||||
public StatisticsSingboxService(Config config, Func<ServerSpeedItem, Task> updateFunc)
|
||||
{
|
||||
_config = config;
|
||||
_updateFunc = updateFunc;
|
||||
@@ -90,7 +90,7 @@ public class StatisticsSingboxService
|
||||
{
|
||||
ParseOutput(result, out var up, out var down);
|
||||
|
||||
_updateFunc?.Invoke(new ServerSpeedItem()
|
||||
await _updateFunc?.Invoke(new ServerSpeedItem()
|
||||
{
|
||||
ProxyUp = (long)(up / 1000),
|
||||
ProxyDown = (long)(down / 1000)
|
||||
|
||||
@@ -6,10 +6,10 @@ public class StatisticsXrayService
|
||||
private ServerSpeedItem _serverSpeedItem = new();
|
||||
private readonly Config _config;
|
||||
private bool _exitFlag;
|
||||
private Action<ServerSpeedItem>? _updateFunc;
|
||||
private readonly Func<ServerSpeedItem, Task>? _updateFunc;
|
||||
private string Url => $"{Global.HttpProtocol}{Global.Loopback}:{AppManager.Instance.StatePort}/debug/vars";
|
||||
|
||||
public StatisticsXrayService(Config config, Action<ServerSpeedItem> updateFunc)
|
||||
public StatisticsXrayService(Config config, Func<ServerSpeedItem, Task> updateFunc)
|
||||
{
|
||||
_config = config;
|
||||
_updateFunc = updateFunc;
|
||||
@@ -39,7 +39,7 @@ public class StatisticsXrayService
|
||||
if (result != null)
|
||||
{
|
||||
var server = ParseOutput(result) ?? new ServerSpeedItem();
|
||||
_updateFunc?.Invoke(server);
|
||||
await _updateFunc?.Invoke(server);
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
Reference in New Issue
Block a user