InvalidOp() публичный статический Метод

public static InvalidOp ( string message ) : void
message string
Результат void
Пример #1
0
        public static T OnUpdating <T>(this T coroutine, Action onUpdating)
            where T : AwaitableCoroutineBase
        {
            if (coroutine is null)
            {
                ThrowHelper.ArgNull(nameof(coroutine));
            }

            if (onUpdating is null)
            {
                ThrowHelper.ArgNull(nameof(onUpdating));
            }

            if (coroutine.IsCanceled)
            {
                ThrowHelper.InvalidOp("Coroutine is already canceled");
            }

            if (coroutine.IsCompleted)
            {
                ThrowHelper.InvalidOp("Coroutine is already completed");
            }

            coroutine.OnUpdating += onUpdating;
            return(coroutine);
        }
        internal void ContinueWith(Action action)
        {
            if (action is null)
            {
                ThrowHelper.ArgNull(nameof(action));
            }

            if (IsCanceled)
            {
                ThrowHelper.InvalidOp("Coroutine is already canceled");
            }

            if (IsCompleted)
            {
                action.Invoke();
                return;
            }

            var runner = ICoroutineRunner.GetContext();

            if (Runner == runner)
            {
                OnCompleted += action;
            }
            else
            {
                OnCompleted += () => runner.Context(action);
            }
        }
        internal void AddOnCanceled(Action onCanceled)
        {
            if (onCanceled is null)
            {
                ThrowHelper.ArgNull(nameof(onCanceled));
            }

            if (IsCompleted)
            {
                ThrowHelper.InvalidOp("Coroutine is already completed");
            }

            if (IsCanceled)
            {
                onCanceled.Invoke();
                return;
            }

            var runner = ICoroutineRunner.GetContext();

            if (Runner == runner)
            {
                OnCalceled += onCanceled;
            }
            else
            {
                OnCalceled += () => runner.Context(onCanceled);
            }
        }
        public void Cancel()
        {
            if (IsCanceled)
            {
                ThrowHelper.InvalidOp("Coroutien is already canceled");
            }

            if (IsCompleted)
            {
                ThrowHelper.InvalidOp("Coroutine is already completed");
            }

            IsCanceled = true;
            OnCalceled?.Invoke();
            OnCalceled  = null;
            OnCompleted = null;
            Runner      = null;

            if (WaitingCoroutines is { })
Пример #5
0
        void ICoroutineRunner.OnUpdate()
        {
            if (IsUpdating)
            {
                ThrowHelper.InvalidOp("Runnner is already updating");
            }

            IsUpdating = true;

            List <Exception> exns = null;

            try
            {
                var contCount = _continuations.Count;

                for (var i = 0; i < contCount; i++)
                {
                    try
                    {
                        _continuations.Dequeue().Invoke();
                    }
                    catch (Exception e)
                    {
                        exns ??= new List <Exception>();
                        exns.Add(e);
                    }
                }

                _coroutines.AddRange(_coroutinesTmp);
                _coroutinesTmp.Clear();

                foreach (var c in _coroutines)
                {
                    if (!c.IsCompleted && !c.IsCanceled)
                    {
                        c.MoveNext();
                    }

                    if (c.Exception is CanceledException)
                    {
                        // hack
                        Internal.Logger.Log($"CoroutineRunner.OnUpdate {c.GetType().Name} is canceled with {c.Exception.GetType()}");
                    }
                    else if (c.Exception is Exception e)
                    {
                        Internal.Logger.Log($"CoroutineRunner.OnUpdate {c.GetType().Name} has {e.GetType()}");

                        exns ??= new List <Exception>();
                        exns.Add(e);
                    }
                    else if (c.IsCanceled)
                    {
                        Internal.Logger.Log($"CoroutineRunner.OnUpdate {c.GetType().Name} is canceled");
                    }
                    else if (c.IsCompleted)
                    {
                        Internal.Logger.Log($"CoroutineRunner.OnUpdate {c.GetType().Name} is completed");
                    }
                    else
                    {
                        _coroutinesTmp.Add(c);
                    }
                }

                Count -= (_coroutines.Count - _coroutinesTmp.Count);

                // Swap
                (_coroutines, _coroutinesTmp) = (_coroutinesTmp, _coroutines);

                _coroutinesTmp.Clear();
            }
            finally
            {
                IsUpdating = false;
            }

            if (exns is { })