Timer

Definitions of a timer.

Members

Enums

TimerCondition
enum TimerCondition

Conditions upon which timers decide whether they are to fire yet, or wait still.

TimerType
enum TimerType

The different kinds of Timers. Either one that yields a random response each time, or one that yields a ordered one.

Functions

getLine
auto getLine()

Yields a line from the lines array, depending on the type of this timer.

nextOrderedLine
auto nextOrderedLine()

Yields an ordered line from the lines array. Which line is selected depends on the value of position.

randomLine
auto randomLine()

Yields a random line from the lines array.

toJSON
auto toJSON()

Serialises this Timer into a JSONValue.

Static functions

fromJSON
auto fromJSON(JSONValue json)

Deserialises a Timer from a JSONValue.

Variables

condition
TimerCondition condition;

What message/time conditions this Timer abides by.

fiber
Fiber fiber;

Workhorse Fiber.

lastMessageCount
ulong lastMessageCount;

The channel message count at last successful trigger.

lastTimestamp
long lastTimestamp;

The timestamp at the last successful trigger.

lines
string[] lines;

The timered lines to send to the channel.

messageCountStagger
long messageCountStagger;

Delay in number of messages before the timer initially comes into effect.

messageCountThreshold
long messageCountThreshold;

How many messages must have been sent since the last announce before we will allow another one.

name
string name;

String name identifier of this timer.

position
size_t position;

The current position, kept to keep track of what line should be yielded next in the case of ordered timers.

suspended
bool suspended;

Whether or not this Timer is suspended and should not output anything.

timeStagger
long timeStagger;

Delay in seconds before the timer initially comes into effect.

timeThreshold
long timeThreshold;

How many seconds must have passed since the last announce before we will allow another one.

type
TimerType type;

What type of Timer this is.

Examples

Timer timer;
timer.lines = [ "abc", "def", "ghi" ];

{
    timer.type = Timer.TimerType.ordered;
    assert(timer.getLine() == "abc");
    assert(timer.getLine() == "def");
    assert(timer.getLine() == "ghi");
    assert(timer.getLine() == "abc");
    assert(timer.getLine() == "def");
    assert(timer.getLine() == "ghi");
}
{
    import std.algorithm.comparison : among;

    timer.type = Timer.TimerType.random;
    bool[string] linesSeen;

    foreach (immutable i; 0..300)
    {
        linesSeen[timer.getLine()] = true;
    }

    assert("abc" in linesSeen);
    assert("def" in linesSeen);
    assert("ghi" in linesSeen);
}