WhenAll <U, V, W, X>(Func <Action <U>, CoroutToken, IEnumerator> rout01, Func <Action <V>, CoroutToken, IEnumerator> rout02, Func <Action <W>, CoroutToken, IEnumerator> rout03, Func <Action <X>, CoroutToken, IEnumerator> rout04) { if (rout01 == null) { throw new ArgumentNullException("rout01"); } if (rout02 == null) { throw new ArgumentNullException("rout02"); } if (rout03 == null) { throw new ArgumentNullException("rout03"); } if (rout04 == null) { throw new ArgumentNullException("rout04"); } if (rout01.Equals(rout02) || rout01.Equals(rout03) || rout01.Equals(rout04) || rout02.Equals(rout03) || rout02.Equals(rout04) || rout03.Equals(rout04)) { throw new ArgumentException("routines could not be equal."); } var corout01 = new Corout <U>(rout01); var corout02 = new Corout <V>(rout02); var corout03 = new Corout <W>(rout03); var corout04 = new Corout <X>(rout04); return(new CoroutInterlace <U, V, W, X>(corout01, corout02, corout03, corout04)); }
void IDisposable.Dispose() { var scheduler = Scheduler.Instance; if (scheduler == null) { throw new NullReferenceException("scheduler could not be null."); } var fence = Corout.CreateFence(this._startIdx); if (this._fnDispose != null) { fence.OnFinally(co => { if (this._fnDispose != null) { this._fnDispose(); this._fnDispose = null; } }); } scheduler.Append(fence); }
private void Clear() { for (int i = 0; i < this._runningCorouts.Count; ++i) { if (this._runningCorouts[i] != null) { this._coroutsToRemove.Enqueue(this._runningCorouts[i]); } } while (this._coroutsToRemove.Count > 0) { Corout corout = this._coroutsToRemove.Dequeue(); if (corout != null) { this._runningCorouts.Remove(corout); var d = corout as IDisposable; if (d != null) { d.Dispose(); d = null; } corout = null; } } }
public static void WaitThen(float waitSecond, Action then) { if (waitSecond < 0.015f) { then(); } else { using (Corout.OpenFence()) Corout.Create(Corout.IEWait(Scheduler.Instance.Second + waitSecond)).OnFinally(co => then()).Start(); } }
public static void WaitThen(int waitStep, Action then) { if (waitStep <= 0) { then(); } else { using (Corout.OpenFence()) Corout.Create(Corout.IEWait(waitStep - 1)).OnFinally(co => then()).Start(); } }
public static Corout <T> Create <T>(Action <Corout <T> > callback) { if (callback == null) { throw new ArgumentNullException("callback"); } var co = new Corout <T>().OnSucceed(callback); co.MoveNext(); return(co); }
/// <summary></summary> /// <param name="coroutine"></param> public bool Contains(Corout coroutine) { if (coroutine == null) { throw new ArgumentNullException("coroutine"); } if (this._runningCorouts != null) { return(this._runningCorouts.Contains(coroutine)); } return(false); }
private bool RunAtIndex(int index) { Corout corout = this._runningCorouts[index]; if (corout != null) { if (corout.IsFence) { if (index > corout.FenceIndex) { return(false); } corout.MoveNext(); //while (corout.MoveNext()) { }; //return (true); } bool nxt = false; do { nxt = corout.MoveNext(); if (!nxt) { this._coroutsToRemove.Enqueue(corout); } } while (nxt && corout.IsSynchronous); if ((corout.AsyncMode == EAsyncMode.Priorize) || (corout.AsyncMode == EAsyncMode.Deferize)) { return(false); } } else { this._runningCorouts.RemoveAt(index); } return(true); }
WhenAll <U, V>(Func <Action <U>, CoroutToken, IEnumerator> rout01, Func <Action <V>, CoroutToken, IEnumerator> rout02) { if (rout01 == null) { throw new ArgumentNullException("rout01"); } if (rout02 == null) { throw new ArgumentNullException("rout02"); } if (rout01.Equals(rout02)) { throw new ArgumentException("routines could not be equal."); } var corout01 = new Corout <U>(rout01); var corout02 = new Corout <V>(rout02); return(new CoroutInterlace <U, V>(corout01, corout02)); }
/// <summary></summary> /// <param name="coroutine"></param> public void Append(Corout coroutine) { if (coroutine == null) { throw new ArgumentNullException("coroutine"); } if (this._runningCorouts.Contains(coroutine)) { throw new Exception("coroutine already scheduled."); } if (coroutine.IsSynchronous) { this._runningCorouts.Insert(0, coroutine); this.Play(); this.Run(); } else { switch (coroutine.AsyncMode) { case EAsyncMode.Priorize: this._runningCorouts.Insert(0, coroutine); this.Play(); break; case EAsyncMode.Deferize: this._runningCorouts.Add(coroutine); this.Play(); break; case EAsyncMode.Normal: default: this._runningCorouts.Add(coroutine); this.Play(); break; } } }
public override bool MoveNext() { if (this._coroutine == null) { return(false); } if (this._coroutine.MoveNext()) { return(true); } if (this._coroutine.Exception != null) { this.AppendError(this._coroutine.Exception); this.Resume(); return(false); } if (this._coroutine.Token.IsCanceled) { this.Token.CancelError(this._coroutine.Token.CancelException); this.Resume(); return(false); } if (this._continuation != null) { this.DisposeCurrent(); this._coroutine = this._continuation(); this._continuation = null; return(true); } this.Resume(); return(false); }
private void Run() { if (this._status == ESchedulerStatus.Play) { for (int i = 0; i < this._runningCorouts.Count; ++i) { if (!this.RunAtIndex(i)) { break; } } } while (this._coroutsToRemove.Count > 0) { Corout corout = this._coroutsToRemove.Dequeue(); if (corout != null) { this._runningCorouts.Remove(corout); if (corout.Exception != null) { throw corout.Exception; } var d = corout as IDisposable; if (d != null) { d.Dispose(); d = null; } corout = null; } } }
internal CoroutRelay(Corout coroutine, Func <Corout> continuation) { this._coroutine = coroutine; this._continuation = continuation; }