internal void Run()
        {
            lock (lockObject)
            {
                var removeList = new LinkedList <LinkedListNode <CoroutineIterator> >();

                for (var node = list.First; node != null; node = node.Next)
                {
                    var iterator = node.Value;
                    current = iterator.Handle;

                    if (!iterator.Update())
                    {
                        iterator.Dispose();
                        removeList.AddLast(node);
                    }
                }
                current = null;

                if (removeList.Count > 0)
                {
                    for (var node = removeList.First; node != null; node = node.Next)
                    {
                        list.Remove(node.Value);
                    }
                }
            }
        }
        /// <summary>
        /// Start the specific coroutine.
        /// </summary>
        /// <param name="coroutine">A coroutine to start.</param>
        /// <returns>A <see cref="CoroutineHandle"/> object to handle the specified coroutine.</returns>
        public CoroutineHandle Start(IEnumerator coroutine)
        {
            if (IsRunning)
            {
                return(new InnerCoroutine(coroutine.ToCoroutine(), current));
            }

            var handle = new PrimaryCoroutine();

            lock (lockObject)
            {
                var iterator = new CoroutineIterator(coroutine.ToCoroutine(), handle);
                list.AddLast(iterator);
            }

            return(handle);
        }
Beispiel #3
0
 public CoroutineIterator(IEnumerator coroutine, PrimaryCoroutine handle)
 {
     this.coroutine = coroutine;
     Handle         = handle;
 }
Beispiel #4
0
 internal InnerCoroutine(IEnumerator enumerator, PrimaryCoroutine primary)
 {
     this.primary = primary;
     Enumerator   = enumerator;
 }