From 1e27a31b8e0eab5251b6b15cfab72fdff5ee1503 Mon Sep 17 00:00:00 2001 From: Romain Lesur Date: Fri, 23 Nov 2018 01:43:14 +0100 Subject: [PATCH] create a timeout promise --- R/wait.R | 13 +++++++++++++ man/timeout.Rd | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 man/timeout.Rd diff --git a/R/wait.R b/R/wait.R index 67940ae..4057998 100644 --- a/R/wait.R +++ b/R/wait.R @@ -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) + }) +} diff --git a/man/timeout.Rd b/man/timeout.Rd new file mode 100644 index 0000000..ca9609e --- /dev/null +++ b/man/timeout.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/wait.R +\name{timeout} +\alias{timeout} +\title{Set a timeout} +\usage{ +timeout(delay = 0) +} +\arguments{ +\item{delay}{Number of seconds before rejecting the promise.} +} +\value{ +A promise that if rejected after a delay of \code{delay} seconds. +} +\description{ +Set a timeout +}