using Fort23.Core;


namespace Fort23.UTool
{


    /// <summary>
    /// 协程锁
    /// </summary>
    public class CoroutineLock : Entity
    {
        public long key;
        public int count;
        public bool isTimeout;
        public string keyName;
        [CustomMethod(CustomMethodType.Awake)]
        public  void Awake( long k,string keyName, int count)
        {
            this.keyName = keyName;
            this.key = k;
            this.count = count;
        }
        [CustomMethod(CustomMethodType.Destroy)]
        public  void Destroy()
        {
            if (!this.isTimeout)
            {
                CoroutineLockComponent.Instance.Notify(this.key, keyName,this.count + 1);
            }
            else
            {
                LogTool.Error($"coroutine lock timeout: {this.keyName} {this.count}");
            }

            this.key = 0;
            this.count = 0;
        }

    }

    public struct CoroutineLockTimer
    {
        public CTask<CoroutineLock> tcs;

        /// <summary>
        /// 持续时间
        /// </summary>
        public int duration;

        public string keyName;
    }
}