public static Task StartAsync(this UVTimer timer, long timeout)
        {
            var tcs = new TaskCompletionSource <object>();

            try {
                timer.Start(timeout, () => {
                    tcs.SetResult(null);
                });
            } catch (Exception e) {
                tcs.SetException(e);
            }
            return(tcs.Task);
        }
示例#2
0
 public void Simple(int times, int spawn)
 {
     var t = new UVTimer();
     int i = 0;
     t.Tick +=  () => {
         i++;
         if (i > times) {
             t.Close();
         }
     };
     t.Start(TimeSpan.FromMilliseconds(spawn));
     var now = Loop.Default.Now;
     Loop.Default.Run();
     Assert.GreaterOrEqual(Loop.Default.Now - now, (ulong)(times * spawn));
     Assert.IsTrue(t.IsClosed);
 }
示例#3
0
        public static Task StartAsync(this UVTimer timer, ulong timeout)
        {
            var tcs = new TaskCompletionSource <object>();

                        #if TASK_STATUS
            HelperFunctions.SetStatus(tcs.Task, TaskStatus.Running);
                        #endif
            try {
                timer.Start(timeout, () => {
                    tcs.SetResult(null);
                });
            } catch (Exception e) {
                tcs.SetException(e);
            }
            return(tcs.Task);
        }
示例#4
0
        public Fanbar(string root, int id)
        {
            Root  = root;
            ID    = id;
            Value = -1;

            timer = new UVTimer(Application.Loop);

            Get(PWM, (val) => {
                Invalid = true;
                Value   = val;
            });


            timer.Start(TimeSpan.FromSeconds(1), () => {
                Get(FanInput, (val) => RPM = val);
            });
        }
示例#5
0
        public void Simple(int times, int spawn)
        {
            var t = new UVTimer();
            int i = 0;

            t.Tick += () => {
                i++;
                if (i > times)
                {
                    t.Close();
                }
            };
            t.Start(TimeSpan.FromMilliseconds(spawn));
            var now = Loop.Default.Now;

            Loop.Default.Run();
            Assert.True(Loop.Default.Now - now >= (ulong)(times * spawn));
            Assert.True(t.IsClosed);
        }
示例#6
0
        public static Task StartAsync(this UVTimer timer, ulong timeout)
        {
            var tcs = new TaskCompletionSource <object>();

#if TASK_STATUS
            HelperFunctions.SetStatus(tcs.Task, TaskStatus.Running);
#endif
            try
            {
                timer.Start(timeout, () =>
                {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
                    tcs.SetResult(null);
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
                });
            }
            catch (Exception e)
            {
                tcs.SetException(e);
            }
            return(tcs.Task);
        }