R/stats_recurse.R

Defines functions dockerstats_recurse

Documented in dockerstats_recurse

#' Call dockerstats() recursively
#'
#' @inheritParams dockerstats
#' @param every Loop duration
#' @param callback function to call on each loop, with the first argument being the result of `dockerstats()`.
#'
#' @return Nothing, primarly called for its side-effect.
#'
#' @export
#' @examples
#' if (interactive()){
#'     if (dockerstats_available()) {
#'         dockerstats_recurse()
#'     }
#' }
dockerstats_recurse <- function(
  ...,
  all = FALSE,
  extra = "",
  every = 1,
  callback = print,
  verbose = TRUE
){
  if (verbose){
    cat("Starting `dockerstats_recurse()`")
    cat("To stop the process, press CTRL + C")
  }

  while(TRUE){
    callback(
      dockerstats(..., all = all, extra  = extra)
    )
    Sys.sleep(every)
  }
}
ColinFay/dockerstats documentation built on May 18, 2020, 11:54 a.m.