Skip to content

Commit f30ee0c

Browse files
committed
Update pacakge authors vignette for mirai_map sync fallback
1 parent 38243e8 commit f30ee0c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

dev/vignettes/_v06-packages.Rmd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,22 @@ You do not need to anticipate whether an end-user will run the code on their own
3939
- Consider pointing to the documentation for `mirai::daemons()`, or re-exporting `daemons()` in your package as a convenience.
4040
- Never include a call to `daemons()` when using `mirai_map()`.
4141
This is important to ensure that there is no accidental recursive creation of daemons on the same machine, for example if your function is used within another package's function that also uses mirai.
42+
+ The exception to this rule is that package authors may decide to provide a fallback to synchronous behaviour to ensure that a map always runs even if the user has not set daemons.
43+
In this case, it is permissible to set synchronous daemons for the duration of the map, if daemons have not been set, and provided that they are reset after the map.
44+
For this purpose, you may use code such as:
45+
```r
46+
with(if (!daemons_set()) daemons(sync = TRUE), {
47+
mirai_map(...)
48+
})
49+
```
4250
- Exceptionally, a `daemons(n = 1, dispatcher = FALSE, .compute = ...)` call may be used to set up a single dedicated daemon, but only if used with a unique value for `.compute`.
4351
A representative example of this usage pattern is `logger::appender_async()`, where the logger package's 'namespace' concept maps directly to mirai's 'compute profile'.
4452

4553
2. The shape and contents of a `status()` call must not be used programmatically, as this user interface is subject to change at any time. Use `info()` instead.
4654
- For the value of `status()$daemons`, instead use `nextget("url")`.
4755

48-
3. `info()` may be used programmatically, but only index into the vector using the name rather than position e.g. `info()[["cumulative"]]` rather than `info()[[2]]`. This is in case other values are added at a later date.
56+
3. `info()` may be used programmatically, but only index into the vector using the name of the element rather than its position e.g. `info()[["cumulative"]]` rather than `info()[[2]]`.
57+
This is in case other values are added at a later date.
4958

5059
4. The functions `unresolved()`, `is_error_value()`, `is_mirai_error()`, and `is_mirai_interrupt()` should be used to test for the relevant state of a mirai or its value.
5160
- The characteristics of their current implementation, e.g. as a logical NA for an 'unresolvedValue', should not be relied upon, as these are subject to change at any time.

vignettes/v06-packages.Rmd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@ You do not need to anticipate whether an end-user will run the code on their own
3232
- Consider pointing to the documentation for `mirai::daemons()`, or re-exporting `daemons()` in your package as a convenience.
3333
- Never include a call to `daemons()` when using `mirai_map()`.
3434
This is important to ensure that there is no accidental recursive creation of daemons on the same machine, for example if your function is used within another package's function that also uses mirai.
35+
+ The exception to this rule is that package authors may decide to provide a fallback to synchronous behaviour to ensure that a map always runs even if the user has not set daemons.
36+
In this case, it is permissible to set synchronous daemons for the duration of the map, if daemons have not been set, and provided that they are reset after the map.
37+
For this purpose, you may use code such as:
38+
```r
39+
with(if (!daemons_set()) daemons(sync = TRUE), {
40+
mirai_map(...)
41+
})
42+
```
3543
- Exceptionally, a `daemons(n = 1, dispatcher = FALSE, .compute = ...)` call may be used to set up a single dedicated daemon, but only if used with a unique value for `.compute`.
3644
A representative example of this usage pattern is `logger::appender_async()`, where the logger package's 'namespace' concept maps directly to mirai's 'compute profile'.
3745

3846
2. The shape and contents of a `status()` call must not be used programmatically, as this user interface is subject to change at any time. Use `info()` instead.
3947
- For the value of `status()$daemons`, instead use `nextget("url")`.
4048

41-
3. `info()` may be used programmatically, but only index into the vector using the name rather than position e.g. `info()[["cumulative"]]` rather than `info()[[2]]`. This is in case other values are added at a later date.
49+
3. `info()` may be used programmatically, but only index into the vector using the name of the element rather than its position e.g. `info()[["cumulative"]]` rather than `info()[[2]]`.
50+
This is in case other values are added at a later date.
4251

4352
4. The functions `unresolved()`, `is_error_value()`, `is_mirai_error()`, and `is_mirai_interrupt()` should be used to test for the relevant state of a mirai or its value.
4453
- The characteristics of their current implementation, e.g. as a logical NA for an 'unresolvedValue', should not be relied upon, as these are subject to change at any time.

0 commit comments

Comments
 (0)