
Expiry.pudu
Pudu27 lines1023 B
1/** @Domain.Expiry.Module — whether a lifetime or an idle limit has run out */2module PuduLangHttpClient.Domain.Expiry34import Std.Math as Math5import PuduLangHttpClient.Constants.Defaults as Defaults6789export fn elapsed(since: Int, lifetime: Int, now: Int) -> Bool {10 lifetime != Defaults.INFINITE && now - since >= lifetime11}121314export fn remaining(deadline: Option[Int], now: Int) -> Option[Int] {15 let at = deadline ?16 Some(Math.max(at - now, 0))17}181920export fn earliest(left: Option[Int], right: Option[Int]) -> Option[Int] {21 match (left, right) {22 case (Some(first), Some(second)) => Some(Math.min(first, second))23 case (Some(first), None) => Some(first)24 case (None, other) => other25 }26}27