public void TestRpcSpeedAsync() { Console.WriteLine("SpeedAsync"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10000; ++i) { long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(i) })); CancellationTokenSource source = new CancellationTokenSource(); var task = RemoteProcedureCall.GetRpcResultAsync(call1Uid, source.Token); var completed = task.Wait(TimeSpan.FromSeconds(1)); if (!completed) { source.Cancel(); } Assert.That(completed, Is.True); Assert.That(task.IsCompleted); var res = RemoteProcedureCall.UnpackRpcValues(task.Result, new [] { NtType.Double }); Assert.AreNotEqual(0, res.Count, "RPC Result empty"); } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public void TestRpcLocalAsync() { Console.WriteLine("LocalAsync"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1); Console.WriteLine("Calling RPC"); long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(2.0) })); Console.WriteLine("Waiting for RPC Result"); CancellationTokenSource source = new CancellationTokenSource(); var task = RemoteProcedureCall.GetRpcResultAsync(call1Uid, source.Token); var completed = task.Wait(TimeSpan.FromSeconds(1)); if (!completed) { source.Cancel(); } Assert.That(completed, Is.True); Assert.That(task.IsCompleted); var call1Result = RemoteProcedureCall.UnpackRpcValues(task.Result, new [] { NtType.Double }); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }