timeout rpc supported
This commit is contained in:
@@ -40,7 +40,8 @@ public partial class Synapse
|
|||||||
Client!.SubscribeAsync(rcSubOpts).Wait();
|
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;
|
string paramJson;
|
||||||
if (param is string strParam)
|
if (param is string strParam)
|
||||||
@@ -77,7 +78,8 @@ public partial class Synapse
|
|||||||
string response;
|
string response;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (tcs.Task.Wait(Options.RpcTimeout * 1000))
|
timeout ??= Options.RpcTimeout;
|
||||||
|
if (tcs.Task.Wait(timeout.Value * 1000))
|
||||||
{
|
{
|
||||||
response = tcs.Task.Result;
|
response = tcs.Task.Result;
|
||||||
logger.LogDebug(
|
logger.LogDebug(
|
||||||
|
|||||||
+6
-4
@@ -88,10 +88,11 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger<Synapse> logge
|
|||||||
/// <param name="method"></param>
|
/// <param name="method"></param>
|
||||||
/// <param name="param"></param>
|
/// <param name="param"></param>
|
||||||
/// <param name="headers"></param>
|
/// <param name="headers"></param>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public SimApiBaseResponse<T> Rpc<T>(string appName, string method, dynamic? param = null,
|
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!");
|
var res = new SimApiBaseResponse(500, "Synapse Rpc Client Disabled!");
|
||||||
if (Options.DisableRpcClient)
|
if (Options.DisableRpcClient)
|
||||||
@@ -100,7 +101,7 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger<Synapse> logge
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var data = FireRpc(appName, method, param, headers);
|
var data = FireRpc(appName, method, param, headers, timeout);
|
||||||
res = JsonSerializer.Deserialize<SimApiBaseResponse<T>>(data, SimApiUtil.JsonOption);
|
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="method"></param>
|
||||||
/// <param name="param"></param>
|
/// <param name="param"></param>
|
||||||
/// <param name="headers"></param>
|
/// <param name="headers"></param>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public SimApiBaseResponse<object> Rpc(string appName, string method, dynamic? param = null,
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user