internal TaskContract(ContinuationEnumerator continuation) : this() { _currentState = states.continuation; _continuation = continuation; //#if DEBUG && !PROFILER // _trace = new StackTrace(0, true); //#endif }
ContinuationEnumerator Start(bool immediate) { Pause(); var continuationWrapper = _continuationEnumerator; var newTask = _taskGenerator != null?_taskGenerator() : _taskEnumerator; if (_sveltoTask._threadSafeSveltoTaskStates.isRunning == true && _sveltoTask._threadSafeSveltoTaskStates.explicitlyStopped == true) { //Stop() Start() causes this (previous continuation wrapper will stop before to start the new one) //Start() Start() is perceived as a continuation of the previous task therefore it won't //cause the continuation wrapper to stop _pendingTask = newTask; _previousContinuationEnumerator = continuationWrapper; continuationWrapper = _continuationEnumerator = new ContinuationEnumerator(); } else { DBC.Tasks.Check.Require(_runner != null, "SetScheduler function has never been called"); if (_taskGenerator == null && _sveltoTask._threadSafeSveltoTaskStates.taskEnumeratorJustSet == false) { #if GENERATE_NAME DBC.Tasks.Check.Assert(newTask.GetType().IsCompilerGenerated() == false, "Cannot restart a compiler generated iterator block, use SetEnumeratorProvider instead ".FastConcat(this.ToString())); #endif newTask.Reset(); } _sveltoTask._stackingTask = new SveltoTaskWrapper <TTask, IRunner <Lean.SveltoTask <TTask> > >(ref newTask); if (_sveltoTask._threadSafeSveltoTaskStates.isRunning == false) { _sveltoTask._threadSafeSveltoTaskStates = new SveltoTaskState(); _sveltoTask._threadSafeSveltoTaskStates.started = true; var taskRoutine = this; _runner.StartCoroutine(ref taskRoutine, immediate); } } Resume(); return(continuationWrapper); }
internal ContinuationEnumerator Run <TRunner>(TRunner runner, ref TTask task) where TRunner : class, IRunner <LeanSveltoTask <TTask> > { _sveltoTask = new SveltoTaskWrapper <TTask, IRunner <LeanSveltoTask <TTask> > >(ref task, runner); #if DEBUG && !PROFILE_SVELTO DBC.Tasks.Check.Require(IS_TASK_STRUCT == true || task != null, "A valid enumerator is required to enable a LeanSveltTask ".FastConcat(ToString())); DBC.Tasks.Check.Require(runner != null, "SetScheduler function has never been called"); #endif _continuationEnumerator = new ContinuationEnumerator(ContinuationPool.RetrieveFromPool()); _threadSafeSveltoTaskStates.started = true; runner.StartCoroutine(this); return(_continuationEnumerator); }
public TaskRoutine(IRunner <TaskRoutine <TTask> > runner) { _sveltoTask = new SveltoTask(); _runner = runner; _continuationEnumerator = new ContinuationEnumerator(); }
internal TaskContract(ContinuationEnumerator continuation) : this() { _currentState = states.continuation; _continuation = continuation; }
TaskContract(ContinuationEnumerator continuation) : this() { _currentState = states.continuation; _returnObjects.continuation = continuation; }
public static void PushBack(ContinuationEnumerator task) { GC.SuppressFinalize(task); //will be register again once pulled from the pool _pool.Enqueue(task); }