Skip to content

Commit 37a8c21

Browse files
authored
Tidy ups for daemons() and mirai_map() (#407)
* Do not resolve compute before require_daemons() * Streamline daemons() branches
1 parent 960c8dc commit 37a8c21

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

R/daemons.R

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,12 @@ daemons <- function(
241241
create_sock(envir, url, cfg[[2L]])
242242
}
243243
create_profile(envir, .compute, 0L, dots)
244+
envir <- NULL
244245
if (length(remote)) {
245246
on.exit(daemons(0L, .compute = .compute))
246247
launch_remote(n = n, remote = remote, .compute = .compute)
247248
on.exit()
248249
}
249-
} else {
250-
daemons(0, .compute = .compute)
251-
return(eval(match.call()))
252250
}
253251
} else {
254252
signal <- is.null(n)
@@ -277,12 +275,26 @@ daemons <- function(
277275
launch_daemons(seq_len(n), dots, envir)
278276
}
279277
create_profile(envir, .compute, n, dots)
280-
} else {
281-
daemons(0, .compute = .compute)
282-
return(eval(match.call()))
278+
envir <- NULL
283279
}
284280
}
285281

282+
is.null(envir) || return({
283+
daemons(0, .compute = .compute)
284+
daemons(
285+
n = n,
286+
url = url,
287+
remote = remote,
288+
dispatcher = dispatcher,
289+
...,
290+
seed = seed,
291+
serial = serial,
292+
tls = tls,
293+
pass = pass,
294+
.compute = .compute
295+
)
296+
})
297+
286298
invisible(`class<-`(.compute, "miraiDaemons"))
287299
}
288300

R/map.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@
154154
#' @export
155155
#'
156156
mirai_map <- function(.x, .f, ..., .args = list(), .promise = NULL, .compute = NULL) {
157-
if (is.null(.compute)) .compute <- .[["cp"]]
158157
require_daemons(.compute = .compute, call = environment())
159158
is.function(.f) || stop(sprintf(._[["function_required"]], typeof(.f)))
160159

0 commit comments

Comments
 (0)