fix strange compiler error

This commit is contained in:
2026-02-09 15:05:34 +01:00
parent c762f94166
commit 82c3cd8c6e

View File

@@ -17,7 +17,7 @@ pub const RateLimiter = struct {
/// Token refill rate (tokens per second) /// Token refill rate (tokens per second)
refill_rate: u64, refill_rate: u64,
/// Last refill timestamp (nanoseconds) /// Last refill timestamp (nanoseconds)
last_refill: std.atomic.Value(i128), last_refill: std.atomic.Value(i64),
/// Mutex for non-atomic operations /// Mutex for non-atomic operations
mutex: std.Thread.Mutex = .{}, mutex: std.Thread.Mutex = .{},
@@ -26,7 +26,7 @@ pub const RateLimiter = struct {
.tokens = std.atomic.Value(u64).init(config.burst_size), .tokens = std.atomic.Value(u64).init(config.burst_size),
.max_tokens = config.burst_size, .max_tokens = config.burst_size,
.refill_rate = config.tokens_per_second, .refill_rate = config.tokens_per_second,
.last_refill = std.atomic.Value(i128).init(time.nanoTimestamp()), .last_refill = std.atomic.Value(i64).init(@intCast(time.nanoTimestamp())),
}; };
} }
@@ -79,14 +79,15 @@ pub const RateLimiter = struct {
/// Refill tokens based on elapsed time /// Refill tokens based on elapsed time
fn refill(self: *RateLimiter) void { fn refill(self: *RateLimiter) void {
const now = time.nanoTimestamp(); const now: i64 = @intCast(time.nanoTimestamp());
const last = self.last_refill.load(.acquire); const last = self.last_refill.load(.acquire);
const elapsed_ns = now - last; const elapsed_ns = now - last;
if (elapsed_ns <= 0) return; if (elapsed_ns <= 0) return;
// Calculate tokens to add (using nanoseconds for precision) // Calculate tokens to add (using nanoseconds for precision)
const elapsed_seconds = @as(u64, @intCast(@divFloor(elapsed_ns, time.ns_per_s))); const elapsed_ns_u64: u64 = @intCast(elapsed_ns);
const elapsed_seconds = elapsed_ns_u64 / time.ns_per_s;
if (elapsed_seconds == 0) return; if (elapsed_seconds == 0) return;
const new_tokens = elapsed_seconds * self.refill_rate; const new_tokens = elapsed_seconds * self.refill_rate;