call_mirai {mirai} | R Documentation |
call_mirai
retrieves the value of a ‘mirai’, waiting for the
asynchronous operation to resolve if it is still in progress.
call_mirai_
is a variant that allows user interrupts, suitable for
interactive use.
call_mirai(aio)
call_mirai_(aio)
aio |
a ‘mirai’ object. |
This function will wait for the async operation to complete if still in progress (blocking).
The ‘mirai’ updates itself in place, so to access the value of a
‘mirai’ x
directly, use call_mirai(x)$data
.
The passed ‘mirai’ (invisibly). The retrieved value is stored
at $data
.
The value of a ‘mirai’ may be accessed at any time at
$data
, and if yet to resolve, an ‘unresolved’ logical NA
will be returned instead.
Using unresolved
on a ‘mirai’ returns TRUE only if
it has yet to resolve and FALSE otherwise. This is suitable for use in
control flow statements such as while
or if
.
If an error occurs in evaluation, the error message is returned as a
character string of class ‘miraiError’ and ‘errorValue’
(the stack trace is available at $stack.trace
on the error
object). is_mirai_error
may be used to test for this.
is_error_value
tests for all error conditions including
‘mirai’ errors, interrupts, and timeouts.
if (interactive()) {
# Only run examples in interactive R sessions
# using call_mirai()
df1 <- data.frame(a = 1, b = 2)
df2 <- data.frame(a = 3, b = 1)
m <- mirai(as.matrix(rbind(df1, df2)), df1 = df1, df2 = df2, .timeout = 1000)
call_mirai(m)$data
# using unresolved()
m <- mirai(
{
res <- rnorm(n)
res / rev(res)
},
n = 1e6
)
while (unresolved(m)) {
cat("unresolved\n")
Sys.sleep(0.1)
}
str(m$data)
}