This page documents synchronous mode, a special execution mode that evaluates mirai tasks immediately in the current process, and the test suite architecture used to verify package functionality.
For information about asynchronous evaluation (the default mode), see Asynchronous Evaluation with mirai(). For error handling and observability in production environments, see Error Handling and Control.
Synchronous mode (sync = TRUE) fundamentally changes how mirai tasks are evaluated by running them immediately in the current R process rather than sending them to background daemons. This mode serves two primary purposes:
browser() and step-through executionWhen synchronous mode is active, all daemon-related arguments to daemons() are ignored, and tasks execute as if they were regular R function calls.
Sources: vignettes/mirai.Rmd720-754 R/daemons.R44-48 R/daemons.R251-255
Call daemons() with sync = TRUE to enable synchronous mode for the default compute profile:
This configuration:
url to local_url() internallydispatcher = FALSEremote, serial, tls, and pass argumentsseed and .compute parametersSources: R/daemons.R251-255 vignettes/mirai.Rmd731-733
Restrict synchronous behavior to a named compute profile:
This allows mixing synchronous and asynchronous profiles within the same session. Tasks sent to the "debug" profile execute synchronously, while other profiles operate normally.
Sources: vignettes/mirai.Rmd724-725 vignettes/mirai.Rmd743-754
Diagram: Synchronous Mode Initialization in daemons()
Sources: R/daemons.R251-255 R/daemons.R647-653 R/daemons.R655-666
Diagram: Async vs Sync Execution Paths
Sources: vignettes/mirai.Rmd722-723
In synchronous mode, the following code paths are altered:
| Normal Path | Sync Path | Location |
|---|---|---|
mirai() creates unresolved object | mirai() evaluates immediately | R/mirai.R22-90 |
| Evaluation in daemon process | Evaluation in host process | R/daemons.R251-255 |
| Result fetched via socket | Result available immediately | R/daemons.R308 |
dispatcher queues tasks | No dispatcher or queue | R/daemons.R252 |
Sources: R/daemons.R251-255 vignettes/mirai.Rmd720-725
Synchronous mode enables interactive debugging sessions using browser():
In async mode, browser() would execute in a background daemon process where interactive input is not available.
Sources: vignettes/mirai.Rmd722-723
The test suite uses implicit synchronous execution when no daemons are set. This provides:
Sources: tests/tests.R17-156
Isolate debugging to specific task types:
Sources: vignettes/mirai.Rmd742-754 man/with_daemons.Rd31-60
The package uses a custom minimal testing framework defined in tests/tests.R1-14:
Diagram: Minitest Framework Structure
Sources: tests/tests.R1-14
| Function | Purpose | Implementation |
|---|---|---|
test_library() | Load package | tests/tests.R2 |
test_true() | Assert TRUE | tests/tests.R3 |
test_false() | Assert FALSE | tests/tests.R4 |
test_null() | Assert NULL | tests/tests.R5 |
test_notnull() | Assert not NULL | tests/tests.R6 |
test_zero() | Assert 0L | tests/tests.R7 |
test_type() | Assert typeof() | tests/tests.R8 |
test_class() | Assert class | tests/tests.R9 |
test_equal() | Assert == | tests/tests.R10 |
test_identical() | Assert identical | tests/tests.R11 |
test_print() | Assert printable | tests/tests.R12 |
test_error() | Assert error with message | tests/tests.R13 |
Each test function invisibly returns TRUE on success or stops execution with an informative error message on failure.
Sources: tests/tests.R1-14
Diagram: Test Suite Organization
Sources: tests/tests.R1-521
Tests basic functionality without daemons:
info() returns NULL when no daemons setstatus() returns list with zero connectionsdaemons(0) returns FALSE when no daemons existSources: tests/tests.R16-75
Tests mirai evaluation with daemons:
.args and .expr parameterscall_mirai() and race_mirai()miraiErroreverywhere() functionalitySources: tests/tests.R76-156
Validates synchronous mode behavior:
Key validation points:
daemons(sync = TRUE) succeedseverywhere() works in sync modelaunch_local() and launch_remote() error appropriatelymissing() test)Sources: tests/tests.R298-309
Tests check for network connectivity before running distributed tests:
Sources: tests/tests.R17 tests/tests.R77-156
Certain tests only run in development environments:
This prevents complex tests (TLS, OpenTelemetry, stress tests) from running on CRAN's test infrastructure where they may be unreliable.
Sources: tests/tests.R265 tests/tests.R312 tests/tests.R338
Tests use explicit sleep calls to ensure daemons connect:
This pattern appears throughout the test suite to avoid race conditions in asynchronous operations.
Sources: tests/tests.R78 tests/tests.R88 tests/tests.R98
Tests verify specific error messages using test_error():
The containing parameter ensures the error message includes expected text.
Sources: tests/tests.R24-38
Diagram: Test Suite Execution Flow
Sources: tests/tests.R17-521
When synchronous mode is tested:
"seq" compute profilewith_daemons() for scopingeverywhere() and immediate executionSources: tests/tests.R298-309
Use synchronous mode for:
browser()Do not use synchronous mode for:
Sources: vignettes/mirai.Rmd720-725
Example pattern for mixed-mode debugging:
This pattern allows investigating specific failures while maintaining normal execution for the bulk of work.
Sources: vignettes/mirai.Rmd742-754 man/with_daemons.Rd32-60
test_* functionsNOT_CRAN guard if test requires complex setupSources: tests/tests.R1-521
Synchronous mode transforms mirai from an asynchronous parallel computing framework into a synchronous, single-process execution model. This dual-mode capability enables:
The test suite demonstrates best practices for using synchronous mode alongside the minitest framework to ensure comprehensive package validation.
Sources: vignettes/mirai.Rmd720-754 R/daemons.R44-48 R/daemons.R251-255 tests/tests.R1-521
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.