SetState() private method

Set the state.
private SetState ( object newState ) : bool
newState object The new state.
return bool
示例#1
0
            /// <summary>
            /// Worker method to execute the action on a thread.
            /// </summary>
            /// <param name="state">(not used)</param>
            /// <remarks>corresponds to doRun in Java version</remarks>
            void ExecuteAction(object state)
            {
                try
                {
                    Var.pushThreadBindings(RT.map(RT.AGENT, _agent));
                    Agent.Nested = PersistentVector.EMPTY;

                    bool hadError = false;

                    try
                    {
                        object oldval = _agent.State;
                        object newval = _fn.applyTo(RT.cons(_agent.State, _args));
                        _agent.SetState(newval);
                        _agent.notifyWatches(oldval, newval);
                    }
                    catch (Exception e)
                    {
                        // TODO: report/callback  (Java TODO)
                        _agent.AddError(e);
                        hadError = true;
                    }

                    if (!hadError)
                    {
                        releasePendingSends();
                    }

                    bool             popped = false;
                    IPersistentStack next   = null;
                    while (!popped)
                    {
                        IPersistentStack prior = _agent._q.Get();
                        next   = prior.pop();
                        popped = _agent._q.CompareAndSet(prior, next);
                    }

                    if (next.count() > 0)
                    {
                        ((Action)next.peek()).execute();
                    }
                }
                finally
                {
                    Nested = null;
                    Var.popThreadBindings();
                }
            }
示例#2
0
            void ExecuteAction(object state)
            {
                try
                {
                    Agent.Nested = PersistentVector.EMPTY;

                    Exception error = null;

                    try
                    {
                        object oldval = _agent.State;
                        object newval = _fn.applyTo(RT.cons(_agent.State, _args));
                        _agent.SetState(newval);
                        _agent.NotifyWatches(oldval, newval);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }

                    if (error == null)
                    {
                        releasePendingSends();
                    }
                    else
                    {
                        Nested = null;  // allow errorHandler to send
                        if (_agent._errorHandler != null)
                        {
                            try
                            {
                                _agent._errorHandler.invoke(_agent, error);
                            }
                            catch (Exception)
                            {
                                // ignore error handler errors
                            }
                        }
                        if (_agent._errorMode == ContinueKeyword)
                        {
                            error = null;
                        }
                    }

                    bool        popped = false;
                    ActionQueue next   = null;
                    while (!popped)
                    {
                        ActionQueue prior = _agent._aq.Get();
                        next   = new ActionQueue(prior._q.pop(), error);
                        popped = _agent._aq.CompareAndSet(prior, next);
                    }

                    if (error == null && next._q.count() > 0)
                    {
                        ((Action)next._q.peek()).execute();
                    }
                }
                finally
                {
                    Nested = null;
                }
            }