Skip to content

Commit

Permalink
simplify some
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Dec 31, 2024
1 parent 402fa4e commit 32ccbe2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 1 addition & 4 deletions R/daemons.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ...,
check_store_url(sock, envir)
},
{
url <- url[1L]
tls <- configure_tls(url, tls, pass, envir, returnconfig = FALSE)
cv <- cv()
dots <- parse_dots(...)
Expand Down Expand Up @@ -516,10 +515,8 @@ tokenized_url <- function(url) sprintf("%s/%s", url, random(12L))
req_socket <- function(url, tls = NULL, resend = 0L)
`opt<-`(socket("req", listen = url, tls = tls), "req:resend-time", resend)

parse_dispatcher <- function(x) {
x <- x[1L]
parse_dispatcher <- function(x)
if (is.logical(x)) 1L + (!is.na(x) && x) else if (x == "process" || x == "thread") 3L else if (x == "none") 1L else 4L
}

parse_dots <- function(...) {
...length() || return("")
Expand Down
2 changes: 1 addition & 1 deletion R/mirai.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ everywhere <- function(.expr, ..., .args = list(), .serial = NULL, .compute = "d
vec[[i]] <- mirai(.expr, ..., .args = .args, .compute = .compute)
} else {
.expr <- c(.block, .expr)
vec <- vector(mode = "list", length = max(status(.compute)[["connections"]], envir[["n"]]))
vec <- vector(mode = "list", length = status(.compute)[["connections"]])
for (i in seq_along(vec))
vec[[i]] <- mirai(.expr, ..., .args = .args, .compute = .compute)
}
Expand Down
4 changes: 3 additions & 1 deletion tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ connection && .Platform[["OS.type"]] != "windows" && Sys.getenv("NOT_CRAN") == "
# TLS tests
connection && Sys.getenv("NOT_CRAN") == "true" && {
Sys.sleep(1L)
test_zero(daemons(url = c("tls+tcp://127.0.0.1:0", "wss://127.0.0.1:0"), pass = "test"))
test_zero(daemons(url = "tls+tcp://127.0.0.1:0", pass = "test"))
test_equal(launch_local(1L), 1L)
Sys.sleep(1L)
test_true(grepl("CERTIFICATE", launch_remote(1L), fixed = TRUE))
Expand Down Expand Up @@ -304,7 +304,9 @@ connection && Sys.getenv("NOT_CRAN") == "true" && {
connection && Sys.getenv("NOT_CRAN") == "true" && {
Sys.sleep(1L)
q <- vector(mode = "list", length = 10000L)
Sys.setenv(R_DEFAULT_PACKAGES = "stats,utils")
test_equal(daemons(4), 4L)
Sys.unsetenv("R_DEFAULT_PACKAGES")
for (i in seq_len(10000L)) {q[[i]] <- mirai(1L); attr(q[[i]], "status") <- status()}
test_equal(sum(unlist(collect_mirai(q))), 10000L)
test_true(all(as.logical(lapply(lapply(q, attr, "status"), is.list))))
Expand Down

0 comments on commit 32ccbe2

Please sign in to comment.