public static void Test1() { var api = new DotqApi(); var mult1 = new MultiplyTask(new Inp { x = 4, y = 5 }); var mult2 = new MultiplyTask(new Inp { x = 4, y = 6 }); var res1 = api.Delay(mult1); var res2 = api.Delay(mult2); ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); var m = new RedisTaskQueue(redis); var resolver = new RedisPromiseServer(); // Thread.Sleep(100); // for (long i = 0; i < m.Length(); i++) // { // var task = m.Dequeue(); // task.Execute(); // resolver.Resolve(task.Promise, task.SerializeResult()); // } // Thread.Sleep(100); // if (res1.GetResult() == 20 && res2.GetResult() == 24) // { // Console.WriteLine("test is successful"); // } }
static void Main(string[] args) { if (args.Length > 0 && args[0] == "worker") { var dotq = new DotqApi(); var worker = dotq.CreateWorker(); worker.StartConsumerLoop(new TimeSpan(0, 0, 50)); } if (args.Length > 0 && args[0] == "client-1") { var dotq = new DotqApi(); var task = new AddTask((5, 5)); var handle = dotq.Delay(task); handle.Wait(); var result = handle.GetResult(); Console.WriteLine($"Result :{result}"); } if (args.Length > 0 && args[0] == "client-2") { var dotq = new DotqApi(); var task = new ListSum(new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); var handle = dotq.Build(task, firstTaskResult => { Console.WriteLine($"first is executed {firstTaskResult}"); var handle2 = dotq.Build(new AddTask((firstTaskResult, 5)), o1 => { Console.WriteLine($"Chain result is {o1}"); });