Skip to content

Commit

Permalink
Expose the {later} loop in controller()
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Apr 10, 2024
1 parent bb75dd7 commit c5f93ac
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Description: In computationally demanding analysis projects,
'clustermq' by Schubert (2019) <doi:10.1093/bioinformatics/btz284>),
and 'batchtools' by Lang, Bischel, and Surmann (2017)
<doi:10.21105/joss.00135>.
Version: 0.9.1.9000
Version: 0.9.1.9002
License: MIT + file LICENSE
URL: https://wlandau.github.io/crew/, https://github.com/wlandau/crew
BugReports: https://github.com/wlandau/crew/issues
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ importFrom(cli,cli_progress_done)
importFrom(cli,cli_progress_update)
importFrom(data.table,rbindlist)
importFrom(getip,getip)
importFrom(later,current_loop)
importFrom(later,later)
importFrom(mirai,call_mirai_)
importFrom(mirai,daemon)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# crew 0.9.1.9001 (development)
# crew 0.9.1.9002 (development)

* Use `.args` rather than `...` in `mirai::mirai()` to make sure arguments continue to be passed as local variables in `mirai` >= 0.13.1.9012.
* Expose the `later` loop in `controller$promise()`.

# crew 0.9.1

Expand Down
6 changes: 6 additions & 0 deletions R/crew_controller.R
Original file line number Diff line number Diff line change
Expand Up @@ -1138,13 +1138,18 @@ crew_class_controller <- R6::R6Class(
#' within the last `seconds_interval` seconds. `FALSE` to auto-scale
#' every time `scale()` is called. Throttling avoids
#' overburdening the `mirai` dispatcher and other resources.
#' @param loop A `later` event loop to assign the background async
#' task that auto-scales workers and polls for resolved tasks.
#' Can come from `later::current_loop()`, `later::global_loop()`,
#' `later::create_loop()`, or similar.
#' @param controllers Not used. Included to ensure the signature is
#' compatible with the analogous method of controller groups.
promise = function(
mode = "one",
seconds_interval = 0.1,
scale = TRUE,
throttle = TRUE,
loop = later::current_loop(),
controllers = NULL
) {
# Tested in tests/interactive/test-promises.R.
Expand All @@ -1155,6 +1160,7 @@ crew_class_controller <- R6::R6Class(
seconds_interval = seconds_interval,
scale = scale,
throttle = throttle,
loop = loop,
controllers = controllers
)
# nocov end
Expand Down
5 changes: 5 additions & 0 deletions R/crew_controller_group.R
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,18 @@ crew_class_controller_group <- R6::R6Class(
#' within the last `seconds_interval` seconds. `FALSE` to auto-scale
#' every time `scale()` is called. Throttling avoids
#' overburdening the `mirai` dispatcher and other resources.
#' @param loop A `later` event loop to assign the background async
#' task that auto-scales workers and polls for resolved tasks.
#' Can come from `later::current_loop()`, `later::global_loop()`,
#' `later::create_loop()`, or similar.
#' @param controllers Not used. Included to ensure the signature is
#' compatible with the analogous method of controller groups.
promise = function(
mode = "one",
seconds_interval = 0.1,
scale = TRUE,
throttle = TRUE,
loop = later::current_loop(),
controllers = NULL
) {
# Tested in tests/interactive/test-promises.R.
Expand Down
2 changes: 1 addition & 1 deletion R/crew_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @importFrom cli cli_progress_bar cli_progress_done cli_progress_update
#' @importFrom data.table rbindlist
#' @importFrom getip getip
#' @importFrom later later
#' @importFrom later current_loop later
#' @importFrom mirai call_mirai_ daemon daemons is_mirai is_mirai_error
#' mirai nextget nextstream saisei status
#' @importFrom nanonext %~>% cv cv_value mclock msleep nng_error random
Expand Down
3 changes: 2 additions & 1 deletion R/utils_promises.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ controller_promise <- function(
seconds_interval,
scale,
throttle,
loop,
controllers
) {
crew_assert(
Expand Down Expand Up @@ -69,7 +70,7 @@ controller_promise <- function(
if (scale) {
.subset2(controller, "scale")(throttle = throttle)
}
later::later(poll, delay = seconds_interval)
later::later(poll, delay = seconds_interval, loop = loop)
}
}
poll()
Expand Down
6 changes: 6 additions & 0 deletions man/crew_class_controller.Rd

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

6 changes: 6 additions & 0 deletions man/crew_class_controller_group.Rd

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

0 comments on commit c5f93ac

Please sign in to comment.