using System;
using System.Collections.Generic;

namespace XGame.Framework.ThreadScheduler
{
    /// <summary>
    /// 框架专用线程调度
    /// </summary>
    internal class FrameworkSchedulers
    {
        private static Queue<Action> _queue;

        internal static void RunOnMainThread(Action action)
        {
            if (_queue == null) _queue = new Queue<Action>();
            _queue.Enqueue(action);
        }

        internal static void Update()
        {
            if (_queue == null) 
                return;
            while (_queue.Count > 0)
            {
                _queue.Dequeue()?.Invoke();
            }
        }

        internal static void Dispose()
        {
            _queue?.Clear();
        }
    }
}
