% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dispatch_checkpoints.R
\name{dispatch_checkpoints}
\alias{dispatch_checkpoints}
\title{Checkpoint Dispatcher}
\usage{
dispatch_checkpoints(
  items,
  target_func,
  checkpoint_file = "batch_checkpoint.rds"
)
}
\arguments{
\item{items}{A vector or list of items to process.}

\item{target_func}{The function to apply to each item.}

\item{checkpoint_file}{Character. The file path for the state cache. Defaults to `"batch_checkpoint.rds"`.}
}
\value{
A list of successfully processed results, or an invisible list with 
\code{status = "cancelled"} if aborted during resumption.
}
\description{
A crash-resilient wrapper for batch processing that silently caches progress 
at defined intervals and interactively recovers from interrupted sessions.
}
\details{
The function provides a safety layer for long-running batch operations:
\enumerate{
  \item Checks for an existing `.rds` checkpoint file. If found, it prompts the user 
      to resume from the last saved index or restart the process.
  \item Prompts the user for a save frequency (e.g., every 100 items).
  \item Executes the `target_func` on each item in `items` within a `tryCatch` block.
  \item If a critical error occurs, it immediately saves the current state to the 
      `checkpoint_file` and halts execution.
  \item Periodically saves the state based on the specified frequency.
  \item Upon successful completion of all items, the temporary checkpoint file is deleted.
}
}
\section{Warning}{

This function modifies files on disk or the global environment. Please ensure you have a backup or are using version control (e.g., Git) before execution.
}

\examples{
if (interactive()) {
  dispatch_checkpoints(items = list(), target_func = print)
}
}
