| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/future_promise.R |
| 3 |
\name{WorkQueue} |
| 4 |
\alias{WorkQueue} |
| 5 |
\title{Future promise work queue} |
| 6 |
\description{ |
| 7 |
Future promise work queue |
| 8 |
|
| 9 |
Future promise work queue |
| 10 |
} |
| 11 |
\details{ |
| 12 |
An \pkg{R6} class to help with scheduling work to be completed. \code{WorkQueue} will only execute work if the \code{can_proceed()} returns \code{TRUE}. For the use case of \code{future}, \code{can_proceed()} defaults to \code{future::nbrOfFreeWorkers() > 0} which will not allow for work to be executed if a \pkg{future} worker is not available. |
| 13 |
|
| 14 |
\code{WorkQueue} will constantly try to start new work once prior work item finishes. However, if \code{can_proceed()} returns \code{FALSE} (no future workers are available) and there is more work to be done, then work is attempted later a random amount of time later using exponential backoff. The exponential backoff will cap out at 10 seconds to prevent unnecessarily large wait times. |
| 15 |
|
| 16 |
Each time \code{WorkQueue} tries to start more work, it will repeat until \code{can_proceed()} returns \code{FALSE} or there is no more work in the \code{queue}. |
| 17 |
} |
| 18 |
\section{Global event loop}{ |
| 19 |
|
| 20 |
|
| 21 |
The global loop is used by default as the internal \code{WorkQueue} "delayed check" uses a single delay check for the whole queue, rather than having each item in the queue attempt to process. |
| 22 |
This behavior might change in the future, but we are not exactly sure how at this point. |
| 23 |
|
| 24 |
If a private \code{later} loop wants to become synchronous by running until all jobs are completed but is waiting on a \code{future_promise()}, the private loop will not complete unless the global loop is allowed to move forward. |
| 25 |
|
| 26 |
However, it is possible to use a private loop inside a user-defined \code{WorkQueue} may work which can be provided directly to \code{future_promise(queue=custom_queue)}. Having a concrete example (or need) will help us understand the problem better. If you have an example, please reach out . |
| 27 |
} |
| 28 |
|
| 29 |
\seealso{ |
| 30 |
\code{\link[=future_promise_queue]{future_promise_queue()}} which returns a \code{WorkQueue} which is cached per R session. |
| 31 |
} |
| 32 |
\keyword{internal} |
| 33 |
\section{Methods}{ |
| 34 |
\subsection{Public methods}{ |
| 35 |
\itemize{ |
| 36 |
\item \href{#method-WorkQueue-new}{\code{WorkQueue$new()}} |
| 37 |
\item \href{#method-WorkQueue-schedule_work}{\code{WorkQueue$schedule_work()}} |
| 38 |
\item \href{#method-WorkQueue-clone}{\code{WorkQueue$clone()}} |
| 39 |
} |
| 40 |
} |
| 41 |
\if{html}{\out{<hr>}} |
| 42 |
\if{html}{\out{<a id="method-WorkQueue-new"></a>}} |
| 43 |
\if{latex}{\out{\hypertarget{method-WorkQueue-new}{}}} |
| 44 |
\subsection{Method \code{new()}}{ |
| 45 |
Create a new \code{WorkQueue} |
| 46 |
\subsection{Usage}{ |
| 47 |
\if{html}{\out{<div class="r">}}\preformatted{WorkQueue$new( |
| 48 |
can_proceed = future_worker_is_free, |
| 49 |
queue = fastmap::fastqueue(), |
| 50 |
loop = later::global_loop() |
| 51 |
)}\if{html}{\out{</div>}} |
| 52 |
} |
| 53 |
|
| 54 |
\subsection{Arguments}{ |
| 55 |
\if{html}{\out{<div class="arguments">}} |
| 56 |
\describe{ |
| 57 |
\item{\code{can_proceed}}{Function that should return a logical value. If \code{TRUE} is returned, then the next scheduled work will be executed. By default, this function checks if \code{\link[future:nbrOfWorkers]{future::nbrOfFreeWorkers()} > 0}} |
| 58 |
|
| 59 |
\item{\code{queue}}{Queue object to use to store the scheduled work. By default, this is a "First In, First Out" queue using \code{\link[fastmap:fastqueue]{fastmap::fastqueue()}}. If using your own queue, it should have the methods \verb{$add(x)}, \verb{$remove()}, \verb{$size()}.} |
| 60 |
|
| 61 |
\item{\code{loop}}{\pkg{later} loop to use for calculating the next delayed check. Defaults to \code{\link[later:create_loop]{later::global_loop()}}. |
| 62 |
Schedule work} |
| 63 |
} |
| 64 |
\if{html}{\out{</div>}} |
| 65 |
} |
| 66 |
} |
| 67 |
\if{html}{\out{<hr>}} |
| 68 |
\if{html}{\out{<a id="method-WorkQueue-schedule_work"></a>}} |
| 69 |
\if{latex}{\out{\hypertarget{method-WorkQueue-schedule_work}{}}} |
| 70 |
\subsection{Method \code{schedule_work()}}{ |
| 71 |
\subsection{Usage}{ |
| 72 |
\if{html}{\out{<div class="r">}}\preformatted{WorkQueue$schedule_work(fn)}\if{html}{\out{</div>}} |
| 73 |
} |
| 74 |
|
| 75 |
\subsection{Arguments}{ |
| 76 |
\if{html}{\out{<div class="arguments">}} |
| 77 |
\describe{ |
| 78 |
\item{\code{fn}}{function to execute when \code{can_proceed()} returns \code{TRUE}.} |
| 79 |
} |
| 80 |
\if{html}{\out{</div>}} |
| 81 |
} |
| 82 |
} |
| 83 |
\if{html}{\out{<hr>}} |
| 84 |
\if{html}{\out{<a id="method-WorkQueue-clone"></a>}} |
| 85 |
\if{latex}{\out{\hypertarget{method-WorkQueue-clone}{}}} |
| 86 |
\subsection{Method \code{clone()}}{ |
| 87 |
The objects of this class are cloneable with this method. |
| 88 |
\subsection{Usage}{ |
| 89 |
\if{html}{\out{<div class="r">}}\preformatted{WorkQueue$clone(deep = FALSE)}\if{html}{\out{</div>}} |
| 90 |
} |
| 91 |
|
| 92 |
\subsection{Arguments}{ |
| 93 |
\if{html}{\out{<div class="arguments">}} |
| 94 |
\describe{ |
| 95 |
\item{\code{deep}}{Whether to make a deep clone.} |
| 96 |
} |
| 97 |
\if{html}{\out{</div>}} |
| 98 |
} |
| 99 |
} |
| 100 |
} |