From 6af68da3ebf97c851fb2b6d2517328f8d708a37d Mon Sep 17 00:00:00 2001 From: xRain Date: Thu, 5 Sep 2024 15:06:44 +0800 Subject: [PATCH] timeout rpc supported --- Synapse/RpcClient.cs | 6 ++++-- Synapse/Synapse.cs | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Synapse/RpcClient.cs b/Synapse/RpcClient.cs index a7d5e6d..85e5825 100644 --- a/Synapse/RpcClient.cs +++ b/Synapse/RpcClient.cs @@ -40,7 +40,8 @@ public partial class Synapse Client!.SubscribeAsync(rcSubOpts).Wait(); } - private string? FireRpc(string app, string action, object? param, Dictionary? headers = null) + private string? FireRpc(string app, string action, object? param, Dictionary? headers = null, + int? timeout = null) { string paramJson; if (param is string strParam) @@ -77,7 +78,8 @@ public partial class Synapse string response; try { - if (tcs.Task.Wait(Options.RpcTimeout * 1000)) + timeout ??= Options.RpcTimeout; + if (tcs.Task.Wait(timeout.Value * 1000)) { response = tcs.Task.Result; logger.LogDebug( diff --git a/Synapse/Synapse.cs b/Synapse/Synapse.cs index 287aefb..6073dc5 100644 --- a/Synapse/Synapse.cs +++ b/Synapse/Synapse.cs @@ -88,10 +88,11 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger logge /// /// /// + /// /// /// public SimApiBaseResponse Rpc(string appName, string method, dynamic? param = null, - Dictionary? headers = null) + Dictionary? headers = null, int? timeout = null) { var res = new SimApiBaseResponse(500, "Synapse Rpc Client Disabled!"); if (Options.DisableRpcClient) @@ -100,7 +101,7 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger logge } else { - var data = FireRpc(appName, method, param, headers); + var data = FireRpc(appName, method, param, headers, timeout); res = JsonSerializer.Deserialize>(data, SimApiUtil.JsonOption); } @@ -114,11 +115,12 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger logge /// /// /// + /// /// public SimApiBaseResponse Rpc(string appName, string method, dynamic? param = null, - Dictionary? headers = null) + Dictionary? headers = null, int? timeout = null) { - return Rpc(appName, method, param, headers); + return Rpc(appName, method, param, headers, timeout); }