setTerminalIfAbsent method
Attempts to persist status as the task's terminal state.
Implementation
@override
Future<bool> setTerminalIfAbsent(
TaskStatus status, {
Duration? ttl,
}) async {
final existing = _entries[status.id];
if (existing != null && existing.expiresAt.isBefore(stemNow())) {
_remove(status.id);
} else if (existing?.status.state.isTerminal ?? false) {
return false;
}
// This method intentionally performs the check and write without an
// asynchronous gap. It is atomic for this single-isolate backend.
_write(status, ttl: ttl);
return true;
}