Example #1
0
        public void Start()
        {
            if (running)
            {
                return;
            }

            running = true;

            InterceptableEnumerator ie = new InterceptableEnumerator(DoStart());

            ie.RegisterCatchBlock(e => { running = false; });
            Executors.RunOnCoroutineNoReturn(ie);
        }
Example #2
0
        protected static InterceptableEnumerator WrapEnumerator(IEnumerator routine, IPromise promise)
        {
            InterceptableEnumerator enumerator = routine is InterceptableEnumerator ? (InterceptableEnumerator)routine : new InterceptableEnumerator(routine);

            if (promise != null)
            {
                enumerator.RegisterConditionBlock(() => !(promise.IsCancellationRequested));
                enumerator.RegisterCatchBlock(e =>
                {
                    if (promise != null)
                    {
                        promise.SetException(e);
                    }

                    if (log.IsErrorEnabled)
                    {
                        log.Error(e);
                    }
                });
                enumerator.RegisterFinallyBlock(() =>
                {
                    if (promise != null && !promise.IsDone)
                    {
                        if (promise.GetType().IsSubclassOfGenericTypeDefinition(typeof(IPromise <>)))
                        {
                            promise.SetException(new Exception("No value given the Result"));
                        }
                        else
                        {
                            promise.SetResult();
                        }
                    }
                });
            }
            return(enumerator);
        }