Exemplo n.º 1
0
        Cothread startCoroutine(IEnumerator routine)
        {
            var th  = new Cothread();
            var iee = callIEnumerable(routine, th);
            var ie  = iee.GetEnumerator();

            th.IE       = ie;
            threads[ie] = th;
            return(th);
        }
Exemplo n.º 2
0
        static IEnumerable callIEnumerable(IEnumerator ie, Cothread th)
        {
            IEnumerable rss;
            bool        ok;
            var         hub = CothreadHub.Instance;

            while (true)
            {
                //check thread is closed?
                if (!hub.threads.ContainsKey(th.IE))
                {
                    yield break;
                }

                ok = false;
                try {
                    ok = ie.MoveNext();
                } catch (Exception err)
                {
                    ok = false;
                    CothreadHub.Log(err);
                }
                if (!ok)
                {
                    yield break;
                }

                rss = null;
                if (ie.Current is CothreadEvent)
                {
                }
                else if (ie.Current is IEnumerable)
                {
                    rss = callIEnumerable(ie.Current as IEnumerable, th);
                }
                else if (ie.Current is IEnumerator)
                {
                    rss = callIEnumerable(ie.Current as IEnumerator, th);
                }
                else if (GlobalAsyncHandle != null)
                {
                    var o1 = GlobalAsyncHandle(ie);
                    if (o1 is IEnumerable)
                    {
                        rss = o1 as IEnumerable;
                    }
                }

                if (rss != null)
                {
                    foreach (var i in rss)
                    {
                        yield return(i);
                    }
                }
                else
                {
                    yield return(ie.Current);
                }
            }
        }
Exemplo n.º 3
0
 static IEnumerable callIEnumerable(IEnumerable iee, Cothread th)
 {
     return(callIEnumerable(iee.GetEnumerator(), th));
 }