public async Task DispatchToRegisteredHandler() { int counter1 = 0; Action <Action> dispatchCounter1 = a => { counter1++; a(); }; int counter2 = 0; Action <Action> dispatchCounter2 = a => { counter2++; a(); }; StaticDispatch.RegisterCallbackDispatcher(dispatchCounter1, 1); StaticDispatch.RegisterCallbackDispatcher(dispatchCounter2, 2); Task.Run(async() => await Task.Delay(100)).Then(() => counter1.Should().Be(1), 1); Task.Run(async() => await Task.Delay(200)).Then(() => counter1.Should().Be(2), 1); Task.Run(async() => await Task.Delay(100)).Then(() => counter2.Should().Be(1), 2); Task.Run(async() => await Task.Delay(200)).Then(() => counter2.Should().Be(2), 2); await Task.Delay(500); counter1.Should().Be(2); counter2.Should().Be(2); }
public override TreeNode GetAstCodeGenerator(SymbolTable t) { List <MIPSCodeGenerator.Expression> codeExpr = new List <MIPSCodeGenerator.Expression>(); for (int i = 0; i < arg.Count; i++) { codeExpr.Add((MIPSCodeGenerator.Expression)Arg[i].GetAstCodeGenerator(t)); //Arg[i].SetGeneratorType(codeExpr[i]); } MIPSCodeGenerator.Expression obj = null; if (name != null && name != "") { obj = new MIPSCodeGenerator.Object(t.AddString(name)); obj.Type = typeName; } else if (exprDispatched != null) { obj = (MIPSCodeGenerator.Expression)exprDispatched.GetAstCodeGenerator(t); exprDispatched.SetGeneratorType(obj); } else { obj = new MIPSCodeGenerator.Object(t.AddString("self"), Line); obj.Type = typeName; } if (Type == null || Type == "") { MIPSCodeGenerator.Dispatch d = new MIPSCodeGenerator.Dispatch(t.AddString(methodName), obj, codeExpr, Line); SetGeneratorType(d); return(d); } else { StaticDispatch sd = new StaticDispatch(t.AddString(methodName), t.AddString(Type), obj, codeExpr, Line); SetGeneratorType(sd); return(sd); } }