From 4465c6216326a421a703c5b9f232e1d1b74b9710 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Fri, 27 Sep 2024 08:39:00 +0200 Subject: [PATCH] Add timeout option to JRPC-Api --- JsonRPC.sln | 42 ++++++++++++++++++ examples/CSharp/Example/CSharp_Example.csproj | 2 +- package.json | 4 +- packages-microsoft-prod.deb | Bin 0 -> 4304 bytes templates/CSharp/CSharp.csproj | 19 ++++---- templates/CSharp/JRpcClient.cs | 27 +++++++++-- 6 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 JsonRPC.sln create mode 100644 packages-microsoft-prod.deb diff --git a/JsonRPC.sln b/JsonRPC.sln new file mode 100644 index 0000000..bc0d713 --- /dev/null +++ b/JsonRPC.sln @@ -0,0 +1,42 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{ECEBC2A1-9382-44B5-94A6-305DC8235859}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharp", "templates\CSharp\CSharp.csproj", "{16231421-DB23-46D0-AFA8-81099E3CF97A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{B6AB75C7-58FC-4F62-AFAA-ED8FEEBF2E1C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CSharp", "CSharp", "{833192BE-67E8-425F-9AA7-23532485682A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharp_Example", "examples\CSharp\Example\CSharp_Example.csproj", "{3BD8D8BF-46ED-4F52-BD78-8B22FF3A77A2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {16231421-DB23-46D0-AFA8-81099E3CF97A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16231421-DB23-46D0-AFA8-81099E3CF97A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16231421-DB23-46D0-AFA8-81099E3CF97A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16231421-DB23-46D0-AFA8-81099E3CF97A}.Release|Any CPU.Build.0 = Release|Any CPU + {3BD8D8BF-46ED-4F52-BD78-8B22FF3A77A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3BD8D8BF-46ED-4F52-BD78-8B22FF3A77A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3BD8D8BF-46ED-4F52-BD78-8B22FF3A77A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3BD8D8BF-46ED-4F52-BD78-8B22FF3A77A2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {16231421-DB23-46D0-AFA8-81099E3CF97A} = {ECEBC2A1-9382-44B5-94A6-305DC8235859} + {833192BE-67E8-425F-9AA7-23532485682A} = {B6AB75C7-58FC-4F62-AFAA-ED8FEEBF2E1C} + {3BD8D8BF-46ED-4F52-BD78-8B22FF3A77A2} = {833192BE-67E8-425F-9AA7-23532485682A} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {ED59162F-B7E7-4EA2-91D4-7F6D1BFBB820} + EndGlobalSection +EndGlobal diff --git a/examples/CSharp/Example/CSharp_Example.csproj b/examples/CSharp/Example/CSharp_Example.csproj index bab5dbb..724c9bc 100644 --- a/examples/CSharp/Example/CSharp_Example.csproj +++ b/examples/CSharp/Example/CSharp_Example.csproj @@ -6,7 +6,7 @@ Exe - net6.0 + net8.0 enable enable diff --git a/package.json b/package.json index b87d366..d40174b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/jrpcgen", - "version": "1.2.17", + "version": "1.2.18", "main": "lib/index.js", "license": "MIT", "packageManager": "yarn@3.1.1", @@ -48,4 +48,4 @@ "dependencies": { "fs-extra": "^10.0.0" } -} \ No newline at end of file +} diff --git a/packages-microsoft-prod.deb b/packages-microsoft-prod.deb new file mode 100644 index 0000000000000000000000000000000000000000..bdb822a5dbac07436955cb0bb1ced444a2e9abd8 GIT binary patch literal 4304 zcmai1c{J2*`?n-aJY=ivSxV0&V;eJxX@+4e4F)qP>tKv+W{hnti7aJLqLQT)DokaI zCq{&jEy-hlQX;ZsiHw==ujlFfe!p|x^Pczp+~<7Gb>G)@pZkyNoX>rIj-K%hA^I7E zynVdLp23=4mEB?h$J-vStzxeOa1Eg~b0wPj^LqjNmr$RkLPLZOt z{_A~hT^Rh=3mzb)G$EdUz`yJqM45n!_memvyl8!0g}NQ3J}1nnsTLhC3aTHAMg^H16jl|5{+|R^~;3xp0K2ZJ)YKf12=V<`T_!zK_xH>z+>4Jg2 z9Rz*%8@^+_!HGM!AaLS`u>Y={(M_R8_w$mD=vnH_6RK;ow}jgi6(L0ja32TZ_Ms<5 z%F7&EtseFKh`%!4n)O(6v$(jNXQt2^<`KxyDAD!@dQRXdU zWUhz?!AvSaqP=cI7qcoQ32tLlB|5ZSC{iB#lZNAcTxO}qsjTT#7MerlR;h#wN#pvO z*YUNd7xJGD*5v2)xl~^}LN`5|Sx0xgxp9zu!A3&NzT3>8e+m7BK8+dkw}R*_cSsNo4wv>ylbrN zp7xfaX8QcE@i^|usG<(i{6Nu1$eWhv4_eB+^g9q)>67x`(s4bhSF+W5Yf4&k&BwAK zI+6$cHtGVU1#BHra#=qf|0tIWtAF}zq-T_P@A-h*7SnBN6t{plT)a{HTf7sWsK? zCvB^8UkbW6okWoX0 z_pu`-XAR{Azk8_jcao@h%|CxfUMP?G|{|?a^KDp>BXhZwRclI=uzGamEb$b zis;5`(w(kdcTG2pZLTV2*Cb~kZhw@-Id(ipQFf2vRh@Y*<-4$qu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 zZh5;yqH8iq_gO$uoRd_|SC{3Oxq8#(Td{L5JJZLPAJ=Vt5F6(2J(hSTeQ#+u^+ic7 z?MHIo=Z6B)`VmaS0juLP6Z%2j@vMyatKU{<#@0W7@ya=UaqCvC;KlRBd-{?}yUwi# zfSW}+5$%+>ABXvwteAypRulgNrZl%^&lKg~|7?O@G~**Yrm)s&Tu$j5N?vCg=--om z*0xIW31-hW=5`MEUQZR9{%&$Z-P|qP`11zazFd|2W6WT_>9kn0=m$=mW~IOq>)xP! zT$Fk@B$q7268!mZ8Huz2s=p!1;?i-54^9SWF_!z{ zvPKo`dY{ccD&AtS-g*?g?v@o0FoT0~U%8yDlxU#$m`5B+kOhu+iCKS5p6ujVXUXtx z1F0z1vG12_hq|^{Bw!{C5Oe}01qJ~@PTU}%)DpS~Fut;Qga!bi`fdtWQG-8e zi8*|kjp(==!AV*9nH^OcDJ=nxgZMUAL(K1q%Oxzu?K9idr~o>6-T@_C!7aou=l7p^ zZR0P1ErBoQiTpXgxRaU9Wt9ETJc+6tu6+vf_X2^)c4#6BiA0$o zk>)5n%K$Rf#ukaBSfXv{;6N)KFq#}}Yk~>DX!-l&oCy>>6^^37EX<;OY1R;;k1q`r z5@dz*qT)gv=vEO>BsC($-VAAtq54NgF=!$75oV!3eYXqQ$%{Me4!87MMr}gAfx8HVO_#`&htWHi2|Y7i+Uf6K6XI zdpbOlaE?NDBok;_eqI&<*3d9B|8w*(yd%^UWM$(LY-52(lk^-T(P%0XY#$k9YY>If zF)+h2kPaAsqCV9p6dP#+ft#H3*Frm;Ls4l4)L;`Ye{7gdh%Lwk4>mYw?SwUPrUdIp z_%P6>X4oi8-6#x_7NG|LNlM~rAG6G@*GBVJI P!+$jqjWzvuEd>1!c$?he literal 0 HcmV?d00001 diff --git a/templates/CSharp/CSharp.csproj b/templates/CSharp/CSharp.csproj index bafd05b..6afe43a 100644 --- a/templates/CSharp/CSharp.csproj +++ b/templates/CSharp/CSharp.csproj @@ -1,9 +1,10 @@ - - - - net6.0 - enable - enable - - - + + + + net6.0 + enable + enable + 10.0 + + + diff --git a/templates/CSharp/JRpcClient.cs b/templates/CSharp/JRpcClient.cs index 502be4b..444851e 100644 --- a/templates/CSharp/JRpcClient.cs +++ b/templates/CSharp/JRpcClient.cs @@ -11,10 +11,12 @@ public class JRpcClient { private JRpcTransport Transport; private IDictionary> Requests; + private int? Timeout = null; - public JRpcClient(JRpcTransport transport) + public JRpcClient(JRpcTransport transport, int? timeout = null) { this.Transport = transport; + this.Timeout = timeout; this.Requests = new Dictionary>(); this.Transport.OnPacket += this.HandlePacket; @@ -87,9 +89,28 @@ public class JRpcClient var task = new TaskCompletionSource(); this.Requests.Add(id, task); - await this.Transport.Write(request.ToJsonString()); + _ = Task.Run(async () => + { + await this.Transport.Write(request.ToJsonString()); + }); - return await task.Task; + if (this.Timeout.HasValue) + { + if (await Task.WhenAny(task.Task, Task.Delay(this.Timeout.Value)) == task.Task) + { + return await task.Task; + } + else + { + this.Requests.Remove(id); + throw new JRpcException("Request Timeout"); + } + + } + else + { + return await task.Task; + } } public async Task SendRequest(string method, JsonArray param)