Clean Up Async Resources
cleanup_async.RdShuts down crew workers and closes nanonext sockets. Should always be called when async simulation completes or errors.
Arguments
- controller
A crew controller object created by
create_controller(). Can be NULL if controller was not successfully created.- socket
A nanonext publisher socket created by
create_pub_socket(). Can be NULL if socket was not successfully created.
Details
Performs graceful shutdown:
Terminates all crew workers (sends shutdown signal)
Closes nanonext publisher socket
Logs cleanup status
This function is safe to call multiple times and handles NULL inputs gracefully (useful for error cleanup).
Always call this function in a tryCatch() finally block to ensure
resources are cleaned up even if the simulation errors.
Examples
if (FALSE) { # \dontrun{
# Typical usage pattern
controller <- NULL
socket <- NULL
tryCatch({
controller <- create_controller(n_workers = 2)
socket <- create_pub_socket(port = 5555)
# ... run simulation ...
}, finally = {
cleanup_async(controller, socket)
})
} # }