Skip to content

Commit

Permalink
Fix #146
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Feb 2, 2024
1 parent 09308df commit f0f6197
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Require `nanonext` >= 0.12.0 and `mirai` >= 0.12.0.
* Return to always re-launching backlogged inactive workers (#79, https://github.com/shikokuchuo/mirai/discussions/95).
* Implement `push_backlog()` and `pop_backlog()` to manage cases when it is not desirable to push to saturated controllers (https://github.com/ropensci/targets/issues/1220).
* Invisibly return the `mirai` object of a task pushed to the controller. This allows users to interact with the task directly, e.g. to create a promise object with `promises::as.promise()` (#146, @jcheng5).

# crew 0.8.0

Expand Down
6 changes: 4 additions & 2 deletions R/crew_controller.R
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ crew_class_controller <- R6::R6Class(
invisible()
},
#' @description Push a task to the head of the task list.
#' @return `NULL` (invisibly).
#' @return Invisibly return the `mirai` object of the pushed task.
#' This allows you to interact with the task directly, e.g.
#' to create a promise object with `promises::as.promise()`.
#' @param command Language object with R code to run.
#' @param data Named list of local data objects in the
#' evaluation environment.
Expand Down Expand Up @@ -444,7 +446,7 @@ crew_class_controller <- R6::R6Class(
if (scale) {
.subset2(self, "scale")(throttle = throttle)
}
invisible()
invisible(task)
},
#' @description Apply a single command to multiple inputs.
#' @details `map()` cannot be used unless all prior tasks are
Expand Down
4 changes: 3 additions & 1 deletion R/crew_controller_group.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ crew_class_controller_group <- R6::R6Class(
walk(control, ~.x$scale(throttle = throttle))
},
#' @description Push a task to the head of the task list.
#' @return `NULL` (invisibly).
#' @return Invisibly return the `mirai` object of the pushed task.
#' This allows you to interact with the task directly, e.g.
#' to create a promise object with `promises::as.promise()`.
#' @param command Language object with R code to run.
#' @param data Named list of local data objects in the
#' evaluation environment.
Expand Down
4 changes: 3 additions & 1 deletion man/crew_class_controller.Rd

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

4 changes: 3 additions & 1 deletion man/crew_class_controller_group.Rd

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

3 changes: 2 additions & 1 deletion tests/testthat/test-crew_controller_group.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ crew_test("crew_controller_group()", {
)
expect_null(x$pop())
# substitute = TRUE # nolint
x$push(
task <- x$push(
command = ps::ps_pid(),
name = "task_pid",
controller = "b",
save_command = TRUE
)
expect_s3_class(task, "mirai")
expect_false(x$empty())
expect_true(x$empty(controllers = "a"))
expect_false(x$empty(controllers = "b"))
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-crew_controller_local.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ crew_test("crew_controller_local()", {
# first task
expect_equal(x$pushed, 0L)
expect_equal(x$popped, 0L)
x$push(
task <- x$push(
command = Sys.getenv("CREW_INSTANCE"),
name = "task",
save_command = TRUE
)
expect_s3_class(task, "mirai")
expect_equal(x$pushed, 1L)
expect_equal(x$popped, 0L)
expect_false(x$empty())
Expand Down

0 comments on commit f0f6197

Please sign in to comment.