Beispiel #1
0
        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 = ContinuationPool.RetrieveFromPool();
            }
            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, IInternalRunner <LeanSveltoTask <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);
        }
Beispiel #2
0
 public TaskRoutine(IInternalRunner <TaskRoutine <TTask> > runner)
 {
     _sveltoTask             = new SveltoTask();
     _runner                 = runner;
     _continuationEnumerator = ContinuationPool.RetrieveFromPool();
 }