Last active
October 24, 2017 18:19
-
-
Save ChrisMissal/90f8eb2de43a9341404d41f23a5d60f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConsistentInterval : IDisposable | |
{ | |
private readonly TimeSpan delay; | |
private readonly CancellationToken cancellationToken; | |
private readonly DateTimeOffset startTime; | |
public ConsistentInterval(TimeSpan delay, CancellationToken cancellationToken) | |
{ | |
this.delay = delay; | |
this.cancellationToken = cancellationToken; | |
this.startTime = DateTimeOffset.UtcNow; | |
} | |
public void Dispose() | |
{ | |
var delayTime = this.startTime.Add(this.delay).Subtract(DateTimeOffset.UtcNow); | |
Task.Delay(delayTime, this.cancellationToken).GetAwaiter().GetResult(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment