Skip to content

Commit e5f13eb

Browse files
committed
Add comments to quick start example
1 parent 749a189 commit e5f13eb

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

README.Rmd

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,29 @@ install.packages("mirai")
5757
```{r}
5858
#| label: exec
5959
library(mirai)
60+
61+
# Set up 5 background processes
6062
daemons(5)
6163
64+
# Send work -- non-blocking, returns immediately
6265
m <- mirai({
6366
Sys.sleep(1)
6467
100 + 42
6568
})
69+
m
6670
71+
# Map work across daemons in parallel
6772
mp <- mirai_map(1:9, \(x) {
6873
Sys.sleep(1)
6974
x^2
7075
})
76+
mp
7177
72-
m
78+
# Collect results when ready
7379
m[]
74-
75-
mp
7680
mp[.flat]
7781
82+
# Shut down
7883
daemons(0)
7984
```
8085

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,33 @@ receive and execute tasks.
4646

4747
``` r
4848
library(mirai)
49+
50+
# Set up 5 background processes
4951
daemons(5)
5052

53+
# Send work -- non-blocking, returns immediately
5154
m <- mirai({
5255
Sys.sleep(1)
5356
100 + 42
5457
})
58+
m
59+
#> < mirai [] >
5560

61+
# Map work across daemons in parallel
5662
mp <- mirai_map(1:9, \(x) {
5763
Sys.sleep(1)
5864
x^2
5965
})
66+
mp
67+
#> < mirai map [0/9] >
6068

61-
m
62-
#> < mirai [] >
69+
# Collect results when ready
6370
m[]
6471
#> [1] 142
65-
66-
mp
67-
#> < mirai map [4/9] >
6872
mp[.flat]
6973
#> [1] 1 4 9 16 25 36 49 64 81
7074

75+
# Shut down
7176
daemons(0)
7277
```
7378

0 commit comments

Comments
 (0)