-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
I am using future_promise() to run calculations that sequentially get better and better. Results are displayed in a shiny app. This works great.
However, we would need a way to pause and resume a WorkQueue. I have built a custom PauseWorkQueue class that adapts can_proceed(), but starting the WorkQueue is subject to all Delay objects running out.
Is there a better way to do this?
Current solution:
PauseQueue <- R6Class("PauseQueue",
inherit = promises:::WorkQueue, # Hier geven we de ouderklasse aan
public = list(
running = TRUE,
queue=fastmap::fastqueue(),
initialize = function() {
super$initialize(can_proceed=function(){
future::nbrOfFreeWorkers() > 0 && self$running
}, queue=self$queue)
},
stop = function() {
self$running <- FALSE
},
start = function() {
self$running <- TRUE
},
isRunning = function() {
self$running & self$queue$size() > 0
}
)
)
queue <- PauseQueue$new()
N <- 10
todo <- purrr::map(seq_len(N), function(i){
f <- promises::future_promise(
expr={
cat("Evaluating... ",i,"\n")
Sys.sleep(0.5)
i
},
queue=queue
)
})
queue$stop()
Metadata
Metadata
Assignees
Labels
No labels