% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/llama.R
\name{llama_set_abort_callback}
\alias{llama_set_abort_callback}
\title{Set or clear the abort callback}
\usage{
llama_set_abort_callback(ctx, fn)
}
\arguments{
\item{ctx}{Context handle returned by [llama_new_context]}

\item{fn}{A zero-argument R function returning a logical scalar,
or `NULL` to clear.}
}
\value{
No return value, called for side effects.
}
\description{
Registers an R function that is called periodically during generation.
If the function returns `TRUE`, the current decode operation is aborted.
Pass `NULL` to remove the callback.
}
\details{
Note: only one callback is active globally — setting a new one replaces
the previous one across all contexts.
}
\examples{
\dontrun{
# Abort after 2 seconds
deadline <- Sys.time() + 2
llama_set_abort_callback(ctx, function() Sys.time() > deadline)
result <- llama_generate(ctx, "Tell me a long story", max_new_tokens = 500L)
llama_set_abort_callback(ctx, NULL)
}
}
