mirai provides these functions for package authors:
require_daemons() - errors and prompts users to set daemons if not already set (with clickable function link if cli package available)daemons_set() - detects if daemons are seton_daemon() - detects if code runs on a daemon (within a mirai() call)register_serial() - registers custom serialization functions, automatically available for all subsequent daemons() callsnextget() - queries compute profile values like ‘url’ (see function documentation). Note: only specifically-documented values are supported interfaces.mirai supports transparent, inter-operable package use. Not relying on global options or environment variables minimizes conflicts between packages.
Important points:
Leave daemons() settings to end-users. As a package author, assume mirai run on whatever resources users have available. Don’t anticipate whether users run code locally, distributed, or mixed.
mirai::daemons() documentation or re-export daemons() for conveniencedaemons() when using mirai_map() to prevent accidental recursive daemon creation (e.g., if your function is used within another package’s mirai-using function)
with(if (!daemons_set()) daemons(sync = TRUE), {
mirai_map(...)
})
daemons(n = 1, dispatcher = FALSE, .compute = ...) for a single dedicated daemon only with a unique .compute value. Example: logger::appender_async() where logger’s ‘namespace’ maps to mirai’s ‘compute profile’.Don’t use status() programmatically. Its interface may change. Use info() instead.
status()$daemons, use nextget("url")Use info() programmatically by name, not position. Index by element name (e.g., info()[["cumulative"]]) not position (e.g., info()[[2]]) in case values are added later.
Use official test functions for mirai state. Use unresolved(), is_error_value(), is_mirai_error(), and is_mirai_interrupt().
CRAN package rules:
dispatcher = FALSE (stays within 2-core limit)daemons(0) at end of examples/test files, then sleep at least 1 second to ensure proper process exitasyncdial or autoexit defaults for daemon() (or functions passing arguments to it like daemons()). This ensures processes exit with the host process.