timeout rpc supported

This commit is contained in:
2024-09-05 15:06:44 +08:00
parent 7dc2ac6a86
commit 6af68da3eb
2 changed files with 10 additions and 6 deletions
+4 -2
View File
@@ -40,7 +40,8 @@ public partial class Synapse
Client!.SubscribeAsync(rcSubOpts).Wait();
}
private string? FireRpc(string app, string action, object? param, Dictionary<string, string>? headers = null)
private string? FireRpc(string app, string action, object? param, Dictionary<string, string>? 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(
+6 -4
View File
@@ -88,10 +88,11 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger<Synapse> logge
/// <param name="method"></param>
/// <param name="param"></param>
/// <param name="headers"></param>
/// <param name="timeout"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public SimApiBaseResponse<T> Rpc<T>(string appName, string method, dynamic? param = null,
Dictionary<string, string>? headers = null)
Dictionary<string, string>? 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<Synapse> logge
}
else
{
var data = FireRpc(appName, method, param, headers);
var data = FireRpc(appName, method, param, headers, timeout);
res = JsonSerializer.Deserialize<SimApiBaseResponse<T>>(data, SimApiUtil.JsonOption);
}
@@ -114,11 +115,12 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger<Synapse> logge
/// <param name="method"></param>
/// <param name="param"></param>
/// <param name="headers"></param>
/// <param name="timeout"></param>
/// <returns></returns>
public SimApiBaseResponse<object> Rpc(string appName, string method, dynamic? param = null,
Dictionary<string, string>? headers = null)
Dictionary<string, string>? headers = null, int? timeout = null)
{
return Rpc<object>(appName, method, param, headers);
return Rpc<object>(appName, method, param, headers, timeout);
}