setTerminalIfAbsent method

  1. @override
Future<bool> setTerminalIfAbsent(
  1. TaskStatus status, {
  2. Duration? ttl,
})
override

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;
}