Asynchronous version of log_call(), for functions that return a
promise. It logs the start when the function is called,
and the finish or the failure when the promise settles, with the time taken
up to that point. A rejection is logged then passed on unchanged. Needs the
promises package.
Usage
async_log_call(f, logger = logger_base(), level = log_levels(), elapsed = TRUE)Arguments
- f
The function to decorate. Usually supplied by
%@%rather than directly.- logger
A logger, such as
logger_message(). See extending_log to use a logging package.- level
A
log_levels()giving the level of the start, finish and error events.- elapsed
Include the time taken in the finish message?
Details
It logs no trace event, as the calls that led to a rejection are no longer
on the stack by the time it settles.
Examples
if (FALSE) { # \dontrun{
fn := async_log_call(logger = logger_message()) %@%
function(x) promises::promise_resolve(x)
promises::then(fn(1), print)
while (!later::loop_empty()) later::run_now(0.05)
} # }
