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); }
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); }
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); }
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); }); }
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); }
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); }