Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-httpclient

Named HTTP clients for Pudu: a client factory, delegating handlers, pooled keep-alive connections, handler lifetimes, logging, and resilience

0.1.1Apache-2.01

InstallClose

Expiry.pudu

Pudu27 lines1023 B

GitHub ↗
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 Defaults67/// Whether something started at `since` has outlived `lifetime` milliseconds at `now`; a lifetime8/// of `Defaults.INFINITE` never runs out and a lifetime of 0 has already run out.9export fn elapsed(since: Int, lifetime: Int, now: Int) -> Bool {10  lifetime != Defaults.INFINITE && now - since >= lifetime11}1213/// Milliseconds left of a deadline at `now`, never below zero, or `None` for no deadline.14export fn remaining(deadline: Option[Int], now: Int) -> Option[Int] {15  let at = deadline ?16  Some(Math.max(at - now, 0))17}1819/// The earlier of two optional deadlines.20export 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