deadline_future 0.1.0
deadline_future: ^0.1.0 copied to clipboard
A Dart package that provides graceful timeout handling by returning cached or fallback values instead of throwing exceptions, ensuring resilient real-time applications and uninterrupted user experiences.
Changelog #
All notable changes to deadline_future are documented in this file.
Format follows Keep a Changelog.
Versioning follows Semantic Versioning.
0.1.0 β 2026-05-29 #
π Initial Release #
Added
Core API
Future<T>.withDeadline(Duration, {...})extension β the primary entry point. Resolves anyFuture<T>with a configurable deadline and a three-tier fallback strategy (live β cached β static fallback β exception).DeadlineResult<T>β immutable result container carrying:valueβ the resolved value (live, cached, or fallback).isTimedOutβ whether the deadline elapsed.source(DeadlineResultSource) βcompleted,cached, orfallback.actualDurationβ how long the original Future ran.resolvedAtβ UTC timestamp of resolution.- Convenience getters:
isLive,isDegraded,isFromCache,isFromFallback. copyWith()for non-destructive mutation (useful in tests).
Smart Cache
DeadlineCacheβ internal in-memory LRU cache with:- Per-entry TTL support (
cacheTtlparameter per call). - Global default TTL (
DeadlineConfig.defaultCacheTtl). - Configurable capacity with FIFO eviction (
maxEntries, default 200). - Lazy TTL eviction on
retrieve(). purgeExpired()for eager eviction.- Self-healing behaviour: late-arriving Futures (after timeout) are automatically stored in the cache for the next call.
- Per-entry TTL support (
Exception Hierarchy
DeadlineFutureExceptionβ sealed base class for all package exceptions.DeadlineExceededExceptionβ thrown when deadline elapses with no cache entry or fallback available. Carriesdeadline,context,occurredAt.InvalidDeadlineDurationExceptionβ thrown synchronously for zero or negativedeadlinevalues.DeadlineCacheExceptionβ defensive exception for cache I/O failures (reserved for future persistent-cache backends).
Global Configuration
DeadlineConfigβ static configuration hub:enableGlobalCache(defaulttrue)defaultCacheTtl(defaultnull= never expire)maxCacheEntries(default200)ignoreErrorsAfterDeadline(defaulttrue)logLevel(DeadlineLogLevel.silentby default)reset()β restores all defaults and clears the cache.clearCache(),evictCacheEntry(key),cacheSizeβ cache helpers.
Logging
DeadlineLoggerβ internal structured logger (not exported publicly).DeadlineLogLevelenum:verbose,info,warning,silent.- All log output is gated β zero cost when
logLevel = silent.
Ergonomic Extras
DeadlineDurationextension onint:3.seconds,500.milliseconds,2.minutes,1.hours
DeadlineFutureListExtension<T>onList<Future<T>>:.withDeadlineAll(deadline, {...})β concurrent batch resolution with shared deadline, per-elementcacheKeys, andonTimeout(index)callback.
Tests
- Unit tests for
DeadlineResult(construction, equality, copyWith, toString). - Unit tests for
DeadlineCache+DeadlineConfig(TTL, eviction, reset). - Unit tests for
DeadlineFutureExtension(all paths, callbacks, exceptions, batch extension, Duration shorthand). - Integration tests covering: crypto price feed, chat, live dashboard batch, retry pattern, and self-healing cache scenarios.
Developer Experience
- Zero runtime dependencies (only
meta: ^1.9.0for@immutable). - Strict analysis options with
strict-casts,strict-inference,strict-raw-typesenabled. example/main.dartwith 10 annotated real-world examples.benchmark/throughput_bench.dartcomparing againstFuture.timeout.doc/getting_started.mdβ step-by-step guide.- BSD-3-Clause license.
[Unreleased] #
Planned #
- Persistent cache backend (Hive / shared_preferences adapter).
withRetryDeadline()β built-in retry loop with per-attempt deadlines.DeadlineStreamβ stream variant (Stream<T>.withDeadline()).DeadlineResult.when()β exhaustive pattern-matching helper.- Web-compatible timer isolation for Flutter Web.
- Coverage badge integration (Coveralls / Codecov).