nextAvailableAt method
Smallest non-null availableAt among entries that have not
yet become available (availableAt > asOf, asOf defaulting
to now), or null if there are none. Drives a TTB-sweep
wake-up timer.
Note the strict-greater-than filter: keys that are already born are excluded. TTB doesn't have TTL's "becomes actionable when crossed → deleted soon after" lifecycle — a born key stays in the store, so only the not-yet-born subset is interesting for a wake-up timer.
Snapshot semantics: best-effort with respect to concurrent mutations, as for KeyValueStore.nextExpiresAt.
MUST be O(1)-or-better than a full-store scan on any backend bundled with this package.
Implementation
@override
Future<DateTime?> nextAvailableAt({DateTime? asOf}) async {
final now = (asOf ?? DateTime.now()).toUtc().millisecondsSinceEpoch;
final v = _db.raw.select(
'SELECT MIN(available_at) m FROM at_data WHERE available_at IS NOT NULL AND available_at > ?;',
[now]).first['m'];
return v == null
? null
: DateTime.fromMillisecondsSinceEpoch(v as int, isUtc: true);
}