Exemplo n.º 1
0
        public long NewOnceTimer(long tillTime, Action <bool> action)
        {
            OnceTimer timer = TimerFactory.Create <OnceTimer, Action <bool> >(action);

            this.timers[timer.InstanceId] = timer;
            AddToTimeId(tillTime, timer.InstanceId);
            return(timer.InstanceId);
        }
Exemplo n.º 2
0
        public async ETTask <bool> WaitAsync(long time)
        {
            long tillTime = TimeHelper.Now() + time;
            ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>();
            OnceWaitTimer timer = TimerFactory.Create <OnceWaitTimer, ETTaskCompletionSource <bool> >(tcs);

            this.timers[timer.InstanceId] = timer;
            AddToTimeId(tillTime, timer.InstanceId);
            return(await tcs.Task);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建一个RepeatedTimer
        /// </summary>
        /// <param name="time"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public long NewRepeatedTimer(long time, Action <bool> action)
        {
            if (time < 30)
            {
                throw new Exception($"repeated time < 30");
            }
            long          tillTime = TimeHelper.Now() + time;
            RepeatedTimer timer    = TimerFactory.Create <RepeatedTimer, long, Action <bool> >(time, action);

            this.timers[timer.InstanceId] = timer;
            AddToTimeId(tillTime, timer.InstanceId);
            return(timer.InstanceId);
        }