CloudCastle Clock

🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano

Deadline — deadlines

Purpose

A “clock + expiry moment” pair: isExpired(), remaining(): TimeSpan, extendedBy() prolongation. Immutable.

What for and how to use

Operation timeouts, token lifetimes, SLAs: Deadline::after($clock, TimeSpan::ofSeconds(30)); deterministic in tests via MockClock.

Example

$deadline = Deadline::after($clock, TimeSpan::ofSeconds(30));
while (!$deadline->isExpired()) {
    $left = $deadline->remaining();   // TimeSpan
    // ... time-bounded work ...
}
$prolonged = $deadline->extendedBy(10.0);

Anti-patterns

Do not compare expiry moments manually — isExpired() encapsulates the boundary (the expiry moment itself is already “expired”).

Lifecycle

stateDiagram-v2
    [*] --> Active: after(clock, span) / until(clock, moment)
    Active --> Active: remaining() > 0
    Active --> Expired: clock reaches expiresAt
    Expired --> Active: extendedBy(span)
    Expired --> [*]

Feature comparison with competitors

Aspect🏆 CloudCastlesymfonycarbonlcobuccibesteergebnis
Clock-bound deadline✅❌❌❌❌❌
Remaining as TimeSpan✅❌❌❌❌❌
Immutable prolongation✅❌❌❌❌❌
Determinism in tests✅❌❌❌❌❌
Total🏆 400000

← Back to the feature list


🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano