Skip to content

Commit

Permalink
have stop_mirai() return either TRUE or FALSE
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Dec 4, 2024
1 parent f36ae0a commit dd30542
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mirai
Type: Package
Title: Minimalist Async Evaluation Framework for R
Version: 1.3.1.9017
Version: 1.3.1.9018
Description: Designed for simplicity, a 'mirai' evaluates an R expression
asynchronously in a parallel process, locally or distributed over the
network, with the result automatically available upon completion. Modern
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# mirai 1.3.1.9017 (development)
# mirai 1.3.1.9018 (development)

#### Architecture Change

Expand Down
5 changes: 1 addition & 4 deletions R/dispatcher.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,13 @@ dispatcher <- function(host, url = NULL, n = NULL, ..., tls = NULL, pass = NULL,
found <- TRUE
break
}
if (found) {
found <- NA
} else {
if (!found)
for (i in seq_along(inq))
if (inq[[i]][["msgid"]] == id) {
inq[[i]] <- NULL
found <- TRUE
break
}
}
send(ctx, found, mode = 2L, block = TRUE)
} else {
status <- c(
Expand Down
23 changes: 13 additions & 10 deletions R/mirai.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,22 @@ collect_mirai <- collect_aio
#' Stops a \sQuote{mirai} if still in progress, causing it to resolve
#' immediately to an \sQuote{errorValue} 20 (Operation canceled).
#'
#' In the case that the \sQuote{mirai} is in execution and an interrupt was
#' sent, the task or a portion of it may have completed before the interrupt is
#' received, and even then it is not always possible to immediately interrupt
#' evaluation (especially if it is compiled code).
#' Using dispatcher allows cancellation of \sQuote{mirai}. In the case that the
#' \sQuote{mirai} is awaiting execution, it is discarded from the queue and
#' never evaluated. In the case it is already in execution, an interrupt will be
#' sent. A successful cancellation request does not guarantee successful
#' cancellation. Note that the task, or a portion of it, may have already
#' completed before the interrupt is received. Even then it is not always
#' possible to immediately interrupt, for example, compiled code. This should be
#' noted particularly if the code carries out side effects during execution,
#' such as writing to files, etc.
#'
#' @inheritParams call_mirai
#'
#' @return A logical value: \code{TRUE} if the cancellation request was
#' definitely successful (task was awaiting execution and has been discarded),
#' \code{NA} if a cancellation request was successfully sent (task was in
#' execution, and will be interrupted), and \code{FALSE} if already completed
#' or previously cancelled. Will always return \code{FALSE} if not using
#' dispatcher.
#' @return Logical \code{TRUE} if the cancellation request was successful (was
#' awaiting execution or in execution), or else \code{FALSE} (if already
#' completed or previously cancelled). Will always return \code{FALSE} if not
#' using dispatcher.
#'
#' @examples
#' if (interactive()) {
Expand Down
23 changes: 13 additions & 10 deletions man/stop_mirai.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ connection && Sys.getenv("NOT_CRAN") == "true" && {
m2 <- mirai({ Sys.sleep(1); res <<- "m2 done" })
Sys.sleep(0.1)
test_true(stop_mirai(m2))
test_true(is.na(stop_mirai(m1)))
test_true(stop_mirai(m1))
test_equal(m2$data, 20L)
test_equal(m1$data, 20L)
test_class("errorValue", mirai(res)[])
Expand Down

0 comments on commit dd30542

Please sign in to comment.