Call the value of a 'mirai', waiting for the the asynchronous operation to resolve if it is still in progress.

call_mirai(mirai)

Arguments

mirai

a 'mirai' object.

Value

The passed 'mirai' (invisibly). The retrieved value is stored in $data.

Details

This function will wait for the async operation to complete if still in progress (blocking).

If an error occured in evaluation, a nul byte 00 (or serialized nul byte) will be returned. is_nul_byte can be used to test for a nul byte.

The 'mirai' updates itself in place, so to access the value of a 'mirai' x directly, use call_mirai(x)$data.

Alternatively

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.

unresolved may also be used on a 'mirai', and returns TRUE only if a 'mirai' has yet to resolve and FALSE otherwise. This is suitable for use in control flow statements such as while or if.

Examples

if (interactive()) {
# Only run examples in interactive R sessions

m <- mirai(x + y + 1, x = 2, y = 3)
m
m$data
Sys.sleep(0.2)
m$data

m <- mirai(as.matrix(df), df = data.frame())
call_mirai(m)$data

m <- mirai({
  res <- rnorm(n)
  res / rev(res)
}, n = 1e6)
while (unresolved(m)) {
  cat("unresolved\n")
  Sys.sleep(0.1)
}
str(m$data)

}