File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed
Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -57,24 +57,29 @@ install.packages("mirai")
5757``` {r}
5858#| label: exec
5959library(mirai)
60+
61+ # Set up 5 background processes
6062daemons(5)
6163
64+ # Send work -- non-blocking, returns immediately
6265m <- mirai({
6366 Sys.sleep(1)
6467 100 + 42
6568})
69+ m
6670
71+ # Map work across daemons in parallel
6772mp <- mirai_map(1:9, \(x) {
6873 Sys.sleep(1)
6974 x^2
7075})
76+ mp
7177
72- m
78+ # Collect results when ready
7379m[]
74-
75- mp
7680mp[.flat]
7781
82+ # Shut down
7883daemons(0)
7984```
8085
Original file line number Diff line number Diff line change @@ -46,28 +46,33 @@ receive and execute tasks.
4646
4747``` r
4848library(mirai )
49+
50+ # Set up 5 background processes
4951daemons(5 )
5052
53+ # Send work -- non-blocking, returns immediately
5154m <- mirai({
5255 Sys.sleep(1 )
5356 100 + 42
5457})
58+ m
59+ # > < mirai [] >
5560
61+ # Map work across daemons in parallel
5662mp <- 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
6370m []
6471# > [1] 142
65-
66- mp
67- # > < mirai map [4/9] >
6872mp [.flat ]
6973# > [1] 1 4 9 16 25 36 49 64 81
7074
75+ # Shut down
7176daemons(0 )
7277```
7378
You can’t perform that action at this time.
0 commit comments