コード例 #1
0
        public static async Task MethodsAsHandlers()
        {
            using var interpreter = new CustomInterpreter();
            var entry1 = interpreter.CreateLogEntry(new BinaryOperationCommand {
                X = 40, Y = 2, Type = BinaryOperation.Add
            }, 1L);

            Equal(1L, entry1.Term);
            Equal(0, interpreter.Value);
            Equal(0, await interpreter.InterpretAsync(entry1));
            Equal(42, interpreter.Value);

            var entry2 = interpreter.CreateLogEntry(new UnaryOperationCommand {
                X = 42, Type = UnaryOperation.Negate
            }, 10L);

            Equal(10L, entry2.Term);
            Equal(1, await interpreter.InterpretAsync(entry2));
            Equal(-42, interpreter.Value);
        }
コード例 #2
0
 protected override ValueTask ApplyAsync(LogEntry entry)
 => new ValueTask(interpreter.InterpretAsync(entry).AsTask());