Learn R Programming

SpaDES.core (version 3.2.1)

.stepEvent: Process one event with recovery wrapping

Description

The single-event step shared by the spades event loop and (later) the simInit .inputObjects phase: take a recovery snapshot (recoverModePre), run the next event via doEvent(), then record any events it added (recoverModePost). Both recovery calls are skipped when recoverMode <= 0.

Usage

.stepEvent(
  sim,
  recoverMode,
  allObjNames,
  thisSpadesCallRandomStr,
  debug,
  notOlderThan,
  events = NULL,
  ...
)

Value

The updated simList (with sim@.xData[["._rmo"]] advanced).

Arguments

sim

A simList.

recoverMode

Numeric/logical; > 0 enables the pre/post snapshots.

allObjNames

Per-module object-name list to snapshot (output objects for the spades loop; input objects for the .inputObjects phase). Passed to recoverModePre().

thisSpadesCallRandomStr

Scratch-dir token for file-backed snapshots.

debug, notOlderThan, events, ...

Passed through to doEvent().

Details

The recovery accumulator is kept on sim@.xData[["._rmo"]] (an environment slot) rather than threaded as a return value. This is deliberate: recoverModePre snapshots the state before the event, and if doEvent() then errors, this function never returns -- so a returned accumulator would be lost exactly when recovery is needed. Mutating the environment slot makes the pre-event snapshot visible to the caller's on.exit handler regardless of whether the event succeeds.