public IEnumerator Do() { using (var defer = new Defer()) { var thread = new System.Threading.Thread(() => { try { Result = _func(); } catch (Exception e) { Error = e; } }); thread.Start(); defer.Add(() => { if (thread.IsAlive) { thread.Abort(); } }); while (thread.IsAlive) { yield return(null); } } }
public IEnumerator Do() { Executor executor = new Executor(); using (var defer = new Defer()) { defer.Add(() => { foreach (Coroutine c in executor) { c.Dispose(); } executor.Clear(); }); for (int i = 0; i < _ms.Length; ++i) { executor.Add(_Do(_ms[i])); } executor.Resume(Coroutine.Delta); while (!executor.Finished) { if (Error != null) { yield break; } yield return(null); executor.Resume(Coroutine.Delta); } if (Error != null) { yield break; } Result = System.Array.ConvertAll(_ms, m => m.Result); } }