Create Async Controller (Auto-detect Backend)
create_controller.RdCreates an async controller for parallel random walk simulation. Automatically selects the appropriate backend:
WebR/WebAssembly: mirai (crew not available)
Native R: crew (preferred for better abstractions)
Value
An async controller object with initialized workers.
Crew backend: R6 crew controller object
Mirai backend: List with crew-compatible interface
Details
The controller manages a pool of R worker processes that execute walker step functions in parallel. Each worker maintains its own local cache of the grid state and subscribes to updates from the main process.
Backend Selection:
WebR/WebAssembly detected by
is_webr()→ uses miraiNative R → uses crew
Both backends provide the same interface:
push(): Submit taskpop(): Retrieve completed taskterminate(): Shutdown workers
Workers are automatically started when the controller is created
and can be cleanly shut down using cleanup_async().
Examples
if (FALSE) { # \dontrun{
# Create controller (auto-detects environment)
controller <- create_controller(n_workers = 2)
# Use controller for parallel tasks
# ... simulation code ...
# Clean up when done
cleanup_async(controller, socket)
} # }