NullWheelTimer

the Header Timer in the wheel

class NullWheelTimer : WheelTimer {}

Members

Functions

onTimeout
void onTimeout()
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From WheelTimer

~this
~this()
Undocumented in source.
onTimeout
void onTimeout()

the function will be called when the timer timeout

rest
void rest(size_t next)

rest the timer

stop
void stop()

stop the time, it will remove from Wheel

isActive
isActive [@property getter]

the time is active

oneShop
bool oneShop;

whether the timer only run once

Examples

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

Meta