|
| 1 | +using BeetleX.XRPC.Clients; |
| 2 | +using BeetleX.XRPC.Packets; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Threading.Tasks; |
| 6 | + |
| 7 | +namespace Client |
| 8 | +{ |
| 9 | + class Program |
| 10 | + { |
| 11 | + static XRPCClient client; |
| 12 | + static IAmount henry, ken, none; |
| 13 | + static void Main(string[] args) |
| 14 | + { |
| 15 | + client = new XRPCClient("localhost", 9090); |
| 16 | + client.Options.ParameterFormater = new JsonPacket();//default messagepack |
| 17 | + henry = client.Create<IAmount>("henry"); |
| 18 | + ken = client.Create<IAmount>("ken"); |
| 19 | + Test(); |
| 20 | + Console.Read(); |
| 21 | + } |
| 22 | + |
| 23 | + static async void Test() |
| 24 | + { |
| 25 | + await Income(); |
| 26 | + await Pay(); |
| 27 | + Console.WriteLine($"henry actor:{await henry.GetValue()} | ken actor:{await ken.GetValue()}"); |
| 28 | + } |
| 29 | + |
| 30 | + static async Task Income() |
| 31 | + { |
| 32 | + List<Task> tasks = new List<Task>(); |
| 33 | + for (int i = 0; i < 10; i++) |
| 34 | + { |
| 35 | + var t = Task.Run(async () => |
| 36 | + { |
| 37 | + for (int k = 0; k < 100; k++) |
| 38 | + { |
| 39 | + await henry.Income(10); |
| 40 | + await ken.Income(10); |
| 41 | + |
| 42 | + } |
| 43 | + }); |
| 44 | + tasks.Add(t); |
| 45 | + } |
| 46 | + await Task.WhenAll(tasks.ToArray()); |
| 47 | + |
| 48 | + } |
| 49 | + |
| 50 | + static async Task Pay() |
| 51 | + { |
| 52 | + List<Task> tasks = new List<Task>(); |
| 53 | + for (int i = 0; i < 10; i++) |
| 54 | + { |
| 55 | + var t = Task.Run(async () => |
| 56 | + { |
| 57 | + for (int k = 0; k < 100; k++) |
| 58 | + { |
| 59 | + await henry.Pay(10); |
| 60 | + await ken.Pay(10); |
| 61 | + |
| 62 | + } |
| 63 | + }); |
| 64 | + tasks.Add(t); |
| 65 | + } |
| 66 | + await Task.WhenAll(tasks); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + public interface IAmount |
| 71 | + { |
| 72 | + Task Income(int value); |
| 73 | + Task Pay(int value); |
| 74 | + Task<int> GetValue(); |
| 75 | + } |
| 76 | +} |
0 commit comments