Skip to content

Pause queue #187

@rfaelens

Description

@rfaelens

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions