votrongdao / ysharp

Automatically exported from code.google.com/p/ysharp
0 stars 0 forks source link

consecutive emit problem #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, 

If you emit signals one by one, StateMachine works like a charme. 
If you emit 2 consecutive signals quickly (by the same thread) the state 
machine has strange behaviors.
In debug mode i found this behavior in MoveNext methods.

        public IState<TValue, TData, TArgs> MoveNext(KeyValuePair<TData, TArgs> input)
        {
            var value = Value;
            Edge<TValue, TData, TArgs> edge;

            if (TryGetEdge(input, false, out edge))
            {
                var next = edge.Target;
                var step = ExecutionStep.LeaveState;

                try
                {
                    var handler = edge.Handler;

                    OnChange(step, next, input.Key, input.Value);
                    if (handler != null)
                        handler(this, step, next, input.Key, input.Value);

                    step = ExecutionStep.EnterState;
                    Value = next;

                    if (handler != null)
                        handler(this, step, value, input.Key, input.Value);

                    OnChange(step, value, input.Key, input.Value);
                }
                catch (Exception exception)
                {
                    if (HandleError(exception, step, input.Key, input.Value, ref next))
                        Value = next;
                }

                return HandleCompletion(ExecutionStep.StateComplete, input);
            }
            else
            {
                throw new InvalidOperationException(String.Format("invalid transition from {0}", value));
            }
        }

Sample: 2 Emit method calls consecutive.
A) The program reaches the first "OnChange (Leave State)" in MoveNext method 
from the first emit call (CORRECT).
B) The program reaches another time the first "OnChange (Leave State)" in 
MoveNext method from the second emit call (NOT CORRECT)
C) The program reaches the second "OnChange (Enter State)" in MoveNext method 
from the second emit call (NOT CORRECT)
D)The program reaches the second "OnChange (Enter State)" in MoveNext method 
from the first emit call (NOT CORRECT)

What i can do?

Original issue reported on code.google.com by mirko.bo...@gmail.com on 17 Jan 2015 at 10:07

GoogleCodeExporter commented 8 years ago
Sorry, it was my fault because i call another emit on second OnChange event 
handling.

Original comment by mirko.bo...@gmail.com on 18 Jan 2015 at 10:24