math: make cast return optional instead of an error

This commit is contained in:
Ali Chraghi
2022-05-22 19:36:59 +04:30
committed by Andrew Kelley
parent ddd5b57045
commit 0e6285c8fc
37 changed files with 152 additions and 175 deletions

View File

@@ -152,7 +152,7 @@ const WindowsImpl = struct {
// Round the nanoseconds to the nearest millisecond,
// then saturating cast it to windows DWORD for use in kernel32 call.
const ms = (timeout_ns +| (std.time.ns_per_ms / 2)) / std.time.ns_per_ms;
timeout_ms = std.math.cast(os.windows.DWORD, ms) catch std.math.maxInt(os.windows.DWORD);
timeout_ms = std.math.cast(os.windows.DWORD, ms) orelse std.math.maxInt(os.windows.DWORD);
// Track if the timeout overflowed into INFINITE and make sure not to wait forever.
if (timeout_ms == os.windows.INFINITE) {