leaseGrantFromResultPayload function

LeaseGrant? leaseGrantFromResultPayload(
  1. Map<String, String> payload
)

Reads a LeaseGrant back out of a step's recorded result payload (the read half of leaseGrantToResultPayload) — null when the payload carries no claim record (a locally-fulfilled step never writes these keys, or the step hasn't resolved yet). The returned grant's ttlSeconds/ heartbeatSeconds are 0 (unrecorded by design — see leaseGrantToResultPayload); a consumer needing the live cadence re-leases rather than reading it from this durable record.

Implementation

LeaseGrant? leaseGrantFromResultPayload(Map<String, String> payload) {
  final leaseId = payload[ClaimResultKeys.leaseId];
  final claimedBy = payload[ClaimResultKeys.claimedBy];
  final fencingToken = payload[ClaimResultKeys.fencingToken];
  if (leaseId == null || claimedBy == null || fencingToken == null) {
    return null;
  }
  return LeaseGrant(
    leaseId: leaseId,
    station: claimedBy,
    ttlSeconds: 0,
    fencingToken: int.tryParse(fencingToken) ?? 0,
    kind: payload[ClaimResultKeys.kind] ?? kDefaultKind,
  );
}