public void Update()
        {
            var timeBudget = 1.0f / 10.0f;
            var totalTime  = 0.0f;

            var count = Tasks.Count;

            var frameCount = AsyncSystem.FrameCount;

            _currentThreadIsProcessingItems = true;

            try
            {
                do
                {
                    var stopwatch = SysDiag.Stopwatch.StartNew();

                    if (this.Tasks.TryDequeue(out var result))
                    {
                        try
                        {
                            if (Thread.CurrentThread == AsyncSystem.MainThread)
                            {
                                AsyncSystem.Log($"Executing Task on \"{Name}\": {result.Id} on frame \"{Time.frameCount}\"");
                            }
                            else
                            {
                                AsyncSystem.Log($"Executing Task on \"{Name}\": {result.Id} on worker frame \"{frameCount}\"");
                            }

                            base.TryExecuteTask(result);
                        }
                        catch (Exception e)
                        {
                            Debug.LogError(e);
                        }
                    }
                    else
                    {
                        break;
                    }

                    stopwatch.Stop();

                    var time = stopwatch.ElapsedMilliseconds / 1000.0f;

                    AsyncSystem.Log($"Executing Task on \"{Name}\": {result.Id} on worker frame \"{frameCount}\" took {Math.Round(time, 3)}s");

                    totalTime += time;
                }while (totalTime < timeBudget && count-- > 0);
            }
            finally
            {
                _currentThreadIsProcessingItems = false;
            }
        }
        public MainThreadCoroutineTaskWrapper(Func <Task> task)
        {
            source = new TaskCompletionSource <object>();

            AsyncSystem.StartOnMainThread(async() =>
            {
                try
                {
                    await task();
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }

                source.SetResult(null);
            });
        }
 public void OnCompleted(Action continuation) => AsyncSystem.StartOnWorkerThread(continuation);
Esempio n. 4
0
 public void OnCompleted(Action continuation)
 {
     AsyncSystem.StartOnMainThread(continuation);
 }