Skip to content

TimerのTickの順番が保証されていない #16

@bleis-tift

Description

@bleis-tift

複数のTimerを使ったときに、先に実行されるTimerの中で長いwaitがあると、場合によっては未来のTickが過去のTickよりも先に実行されてしまう。

var tl = new Timeline(origin);

var timerA = tl.CreateTimer(TimeSpan.FromSeconds(5));
var waitA = tl.CreateWaiter(TimeSpan.FromSeconds, 10, 2, 2, 2, 2);
var historyA = new List<DateTime>();
timerA.Tick += (sender, arg) => { historyA.Add(tl.UtcNow); waitA(); };

var timerB = tl.CreateTimer(TimeSpan.FromSeconds(5));
var waitB = tl.CreateWaiter(TimeSpan.FromSeconds, 2, 2, 2, 2, 2);
var historyB = new List<DateTime>();
timerB.Tick += (sender, arg) => { historyB.Add(tl.UtcNow); waitB(); };

tl.WaitForTime(TimeSpan.FromSeconds(29));

var exceptedHistory = Enumerable.Repeat(origin, 5).Select((d, i) => d + TimeSpan.FromSeconds(5 * (i + 1))).ToArray();
Assert.That(historyA.ToArray(), Is.EqualTo(exceptedHistory));
// ここで、historyBが00:05, 00:10, 00:15, 00:20, 00:25になっていてほしいが、
// timerAの一回目のTickによって、00:10, 00:15のTickが先に実行されてしまい、
// 00:10, 00:15, 00:05, 00:20, 00:25となってしまう
Assert.That(historyB.ToArray(), Is.EqualTo(exceptedHistory));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions