Asynchronous results, TailcatListener$serve(), and TailcatConnection$read_loop() only make progress while the later event loop runs. At the console and inside Shiny that happens on its own; a script run with Rscript has to run the loop itself. These functions do that.
Arguments
- promise
A promise, or anything
promises::is.promising()accepts.- timeout
Seconds to wait;
Inf(the default) waits indefinitely and0runs the callbacks that are already due, without waiting. Whentailcat_wait()times out it raises atailcat_timeouterror; the operation behind the promise keeps going (cancel it withtailcat_cancel()if it should not).- until
A function of no arguments that returns
TRUEwhen the loop should stop, orNULL. It is called before each turn of the loop.
Value
tailcat_wait() returns the promise's value. tailcat_run() returns, invisibly, TRUE if until() returned TRUE and FALSE if the timeout ran out.
Details
tailcat_wait() runs the event loop until promise settles and returns its value, or signals the condition it was rejected with, so a script can use an _async() method like a blocking one. tailcat_run() runs the event loop until until() returns TRUE or the timeout runs out; with until = NULL it runs until the timeout runs out, which with the default timeout = Inf keeps a server script serving until it is interrupted.
Both run the current later loop (later::current_loop()) and can be interrupted. Nothing else in the script runs meanwhile, except what the event loop runs.
Examples
if (FALSE) { # \dontrun{
cl = TailcatClient$new(address)
conn = tailcat_wait(cl$dial_async(8080), timeout = 30)
srv = TailcatServer$new()
lst = srv$listen(8080)
lst$serve(handler)
tailcat_run(until = function() lst$is_closed)
} # }