the function will be called when the timer timeout
rest the timer
stop the time, it will remove from Wheel
the time is active
whether the timer only run once
import std.datetime; import core.thread; import std.exception; import tame.io.stdio; class TestWheelTimer : WheelTimer { this() { time = Clock.currTime; } override void onTimeout() nothrow @trusted { collectException(writeln("\nid is ", id, " \tcurrTime: ", Clock.currTime.toSimpleString(), "\tnew time: ", time.toSimpleString())); } size_t id; private SysTime time; } writeln("start"); auto wheel = new TimingWheel(5); auto timers = new TestWheelTimer[5]; foreach (tm; 0 .. 5) { timers[tm] = new TestWheelTimer; } foreach (i, timer; timers) { timer.id = i; wheel.addTimer(timer); writeln("i = ", i); } writeln("prevWheel(5) _now = ", wheel._now); wheel.prevWheel(5); Thread.sleep(2.seconds); timers[4].stop(); writeln("prevWheel(5) _now = ", wheel._now); wheel.prevWheel(5); Thread.sleep(2.seconds); writeln("prevWheel(3) _now = ", wheel._now); wheel.prevWheel(3); assert(wheel._now == 3); timers[2].rest(); timers[4].rest(); writeln("rest prevWheel(2) _now = ", wheel._now); wheel.prevWheel(2); assert(wheel._now == 0); foreach (u; 0 .. 20) { Thread.sleep(2.seconds); writeln("prevWheel() _now = ", wheel._now); wheel.prevWheel(); }
the Header Timer in the wheel