Windowed
Windowed divides a timeline into interval-long windows,
and sleeps until the nearest window boundary every time it recurs.
For example,
Schedule.Windowed(TimeSpan.FromSeconds(10));
Produces,
10s 10s 10s 10s
|----------|----------|----------|----------|
|action------|sleep---|act|-sleep|action----|
DateTimeOffset now = new DateTimeOffset(2021, 1, 1, 0, 0, 0, TimeSpan.Zero);
using var dates = new[]
{
now,
now + TimeSpan.FromSeconds(6),
now + TimeSpan.FromSeconds(1),
now + TimeSpan.FromSeconds(4),
}
.AsEnumerable()
.GetEnumerator();
Schedule windowed = Schedule.Windowed(
TimeSpan.FromSeconds(5),
currentTimeFunction: () => dates.MoveNext() ? dates.Current : now
);
| Duration |
|---|
| 4 seconds |
| 4 seconds |
| 1 second |
| 5 seconds |
| 5 seconds |