Skip to content

Commit 9ee6fac

Browse files
committed
docs
1 parent ed8c15b commit 9ee6fac

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This library require from Timer class to implement method `id()` which must retu
3333
`ticksUntilNextEvent()` return number of ticks without timers.
3434

3535
#### timeUntilNextEvent ####
36-
`timeUnitNextEvent(Tick)` using provided tick duration return real time to next timer.
36+
`timeUnitNextEvent(Tick)` return real time to next timer using provided tick duration.
3737

3838
Here is complete example with comments
3939

docs.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
"name": "timeUntilNextEvent",
223223
"type": "Duration(const Duration tick)",
224224
"endchar": 5,
225-
"endline": 462,
225+
"endline": 465,
226226
"comment": "Time until next scheduled timer event.\nParams:\ntick = your accepted tick duration.\nReturns: msecs until next event. Can be zero or negative in case you have already expired events.\n\n"
227227
},
228228
{
@@ -232,7 +232,7 @@
232232
"name": "W"
233233
}
234234
],
235-
"line": 470,
235+
"line": 473,
236236
"kind": "template",
237237
"char": 10,
238238
"members": [
@@ -246,13 +246,13 @@
246246
"name": "ticks"
247247
}
248248
],
249-
"line": 470,
249+
"line": 473,
250250
"kind": "function",
251251
"char": 10,
252252
"name": "advance",
253253
"type": "(ulong ticks)",
254254
"endchar": 5,
255-
"endline": 522
255+
"endline": 525
256256
}
257257
],
258258
"name": "advance",
@@ -264,7 +264,7 @@
264264
}
265265
],
266266
"name": "TimingWheels",
267-
"comment": "\nThis structure implements scheme 6.2 thom the\nhttp://www.cs.columbia.edu/~nahum/w6998/papers/sosp87-timing-wheels.pdf\nIt supports several primitives:\n1. schedule timer in the future.\n2. cancel timer.\n3. time step (advance) - all timers expired at current time tick are extracted from wheels.\nEach operation take O(1) time.\n\nExample:\n$(DDOX_UNITTEST_HEADER __unittest_L676_C1)\n---\nimport std;\nglobalLogLevel = LogLevel.info;\nauto rnd = Random(142);\n\n/// track execution\nint counter;\nSysTime last = Clock.currTime;\n\n/// this is our Timer\nclass Timer\n{\n static ulong __id;\n private ulong _id;\n private string _name;\n this(string name)\n {\n _id = __id++;\n _name = name;\n }\n /// must provide id() method\n ulong id()\n {\n return _id;\n }\n}\n\nenum IOWakeUpInterval = 100; // to simulate random IO wakeups in interval 0 - 100.msecs\n\n// each tick span 5 msecs - this is our link with time in reality\nenum Tick = 5.msecs;\nTimingWheels!Timer w;\n\nauto durationToTicks(Duration d)\n{\n return d/Tick;\n}\nvoid process_timer(Timer t)\n{\n switch(t._name)\n {\n case \"periodic\":\n writefln(\"@ %s - delta: %sms (should be 50ms)\", t._name, (Clock.currTime - last).split!\"msecs\".msecs);\n last = Clock.currTime;\n counter++;\n w.schedule(t, durationToTicks(50.msecs)); // rearm\n break;\n default:\n writefln(\"@ %s\", t._name);\n break;\n }\n}\n\n//\n// start one arbitrary timer and one periodic timer\n//\nauto some_timer = new Timer(\"some\");\nauto periodic_timer = new Timer(\"periodic\");\nw.schedule(some_timer, durationToTicks(32.msecs));\nw.schedule(periodic_timer, durationToTicks(50.msecs));\n\nwhile(counter < 10)\n{\n auto randomIoInterval = uniform(0, IOWakeUpInterval, rnd).msecs;\n auto nextTimerEvent = max(w.timeUntilNextEvent(Tick), 0.msecs);\n // wait for what should happen earlier\n auto time_to_sleep = min(randomIoInterval, nextTimerEvent);\n writefln(\"* sleep until timer event or random I/O for %s\", time_to_sleep);\n Thread.sleep(time_to_sleep);\n // if we waked up early by the IO event then timeUntilNextEvent will be positive\n // otherwise it will be <= 0 and we have something to process.\n while(w.timeUntilNextEvent(Tick) <= 0.msecs)\n {\n auto ticks = w.ticksUntilNextEvent();\n auto wr = w.advance(ticks);\n foreach(t; wr.timers)\n {\n process_timer(t);\n }\n }\n // some random processing time\n Thread.sleep(uniform(0, 5, rnd).msecs);\n}\n\n---\n$(DDOX_UNITTEST_FOOTER __unittest_L676_C1)\n"
267+
"comment": "\nThis structure implements scheme 6.2 thom the\nhttp://www.cs.columbia.edu/~nahum/w6998/papers/sosp87-timing-wheels.pdf\nIt supports several primitives:\n1. schedule timer in the future.\n2. cancel timer.\n3. time step (advance) - all timers expired at current time tick are extracted from wheels.\nEach operation take O(1) time.\n\nExample:\n$(DDOX_UNITTEST_HEADER __unittest_L679_C1)\n---\nimport std;\nglobalLogLevel = LogLevel.info;\nauto rnd = Random(142);\n\n/// track execution\nint counter;\nSysTime last = Clock.currTime;\n\n/// this is our Timer\nclass Timer\n{\n static ulong __id;\n private ulong _id;\n private string _name;\n this(string name)\n {\n _id = __id++;\n _name = name;\n }\n /// must provide id() method\n ulong id()\n {\n return _id;\n }\n}\n\nenum IOWakeUpInterval = 100; // to simulate random IO wakeups in interval 0 - 100.msecs\n\n// each tick span 5 msecs - this is our link with time in reality\nenum Tick = 5.msecs;\nTimingWheels!Timer w;\n\nauto durationToTicks(Duration d)\n{\n return d/Tick;\n}\nvoid process_timer(Timer t)\n{\n switch(t._name)\n {\n case \"periodic\":\n writefln(\"@ %s - delta: %sms (should be 50ms)\", t._name, (Clock.currTime - last).split!\"msecs\".msecs);\n last = Clock.currTime;\n counter++;\n w.schedule(t, durationToTicks(50.msecs)); // rearm\n break;\n default:\n writefln(\"@ %s\", t._name);\n break;\n }\n}\n\n//\n// start one arbitrary timer and one periodic timer\n//\nauto some_timer = new Timer(\"some\");\nauto periodic_timer = new Timer(\"periodic\");\nw.schedule(some_timer, durationToTicks(32.msecs));\nw.schedule(periodic_timer, durationToTicks(50.msecs));\n\nwhile(counter < 10)\n{\n auto randomIoInterval = uniform(0, IOWakeUpInterval, rnd).msecs;\n auto nextTimerEvent = max(w.timeUntilNextEvent(Tick), 0.msecs);\n // wait for what should happen earlier\n auto time_to_sleep = min(randomIoInterval, nextTimerEvent);\n writefln(\"* sleep until timer event or random I/O for %s\", time_to_sleep);\n Thread.sleep(time_to_sleep);\n // if we waked up early by the IO event then timeUntilNextEvent will be positive\n // otherwise it will be <= 0 and we have something to process.\n while(w.timeUntilNextEvent(Tick) <= 0.msecs)\n {\n auto ticks = w.ticksUntilNextEvent();\n auto wr = w.advance(ticks);\n foreach(t; wr.timers)\n {\n process_timer(t);\n }\n }\n // some random processing time\n Thread.sleep(uniform(0, 5, rnd).msecs);\n}\n\n---\n$(DDOX_UNITTEST_FOOTER __unittest_L679_C1)\n"
268268
}
269269
],
270270
"comment": "\n",

0 commit comments

Comments
 (0)