IEnumerator CalculateAndShowNumber() //this will run on another thread
        {
            while (true)
            {
                IEnumerator enumerator = FindPrimeNumber((rnd1.Next() % 1000));

                yield return(enumerator);

                long result = (long)enumerator.Current * 333;

                taskRoutine.SetEnumerator(SetColor(result));
                yield return(taskRoutine.Start()); //yep the thread will wait for this other task to finish on the mainThreadScheduler
            }
        }
Exemple #2
0
    public IEnumerator TestUnityWaitInParallel()
    {
        var updateMonoRunner = new UpdateMonoRunner("test1");
        ITaskRoutine <IEnumerator> taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(updateMonoRunner);
        ParallelTaskCollection     pt          = new ParallelTaskCollection();

        pt.Add(new WaitForSecondsUnity().GetEnumerator());
        pt.Add(new WaitForSecondsUnity().GetEnumerator());
        taskRoutine.SetEnumerator(pt);
        taskRoutine.Start();
        DateTime then = DateTime.Now;

        while (taskRoutine.isRunning == true)
        {
            yield return(null);
        }
        updateMonoRunner.Dispose();
        var totalSeconds = (DateTime.Now - then).TotalSeconds;

        Assert.That(totalSeconds, Is.InRange(0.9, 1.1));
    }