Skip to content

Commit

Permalink
create a timeout promise
Browse files Browse the repository at this point in the history
  • Loading branch information
RLesur committed Nov 23, 2018
1 parent 8c9c395 commit 1e27a31
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions R/wait.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@ wait <- function(promise, delay = 0) {promises::then(
}
)
}


#' Set a timeout
#'
#' @param delay Number of seconds before rejecting the promise.
#'
#' @return A promise that if rejected after a delay of `delay` seconds.
#' @export
timeout <- function(delay = 0) {
promises::promise(function(resolve, reject) {
later::later(~ reject(paste("The delay of", delay, "seconds expired.\n")), delay)
})
}
17 changes: 17 additions & 0 deletions man/timeout.Rd

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

0 comments on commit 1e27a31

Please sign in to comment.