26 lines
453 B
C#
26 lines
453 B
C#
using System;
|
|
|
|
namespace LLib;
|
|
|
|
public struct Throttle
|
|
{
|
|
private long _nextAllowedMs;
|
|
|
|
public readonly bool IsReady => Environment.TickCount64 >= _nextAllowedMs;
|
|
|
|
public bool TryReset(double cooldownSeconds)
|
|
{
|
|
long tickCount = Environment.TickCount64;
|
|
if (tickCount < _nextAllowedMs)
|
|
{
|
|
return false;
|
|
}
|
|
_nextAllowedMs = tickCount + (long)(cooldownSeconds * 1000.0);
|
|
return true;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_nextAllowedMs = 0L;
|
|
}
|
|
}
|