Skip to contents

Shuts down crew workers and closes nanonext sockets. Should always be called when async simulation completes or errors.

Usage

cleanup_async(controller, socket)

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.

Value

NULL (invisibly). Side effect: workers stopped, sockets closed.

Details

Performs graceful shutdown:

  1. Terminates all crew workers (sends shutdown signal)

  2. Closes nanonext publisher socket

  3. 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)
})
} # }