Retrieve the value of an asynchronous Aio operation, waiting for the operation to complete if still in progress.
call_aio(aio)
The passed object (invisibly).
an Aio (object of class 'sendAio' or 'recvAio').
Aio values may be accessed directly at $result
for a 'sendAio',
and $data
for a 'recvAio'. If the Aio operation is yet to complete,
an 'unresolved' logical NA will be returned. Once complete, the resolved
value will be returned instead.
unresolved
may also be used, which returns TRUE only if an
Aio or Aio value has yet to resolve and FALSE otherwise. This is suitable
for use in control flow statements such as while
or if
.
For a 'recvAio', the received value may be retrieved at $data
.
For a 'sendAio', the send result may be retrieved at $result
. This
will be zero on success, or else an integer error code.
To access the values directly, use for example on a 'recvAio' x
:
call_aio(x)$data
.
For a 'recvAio', if an error occurred in unserialization or conversion of the message data to the specified mode, a raw vector will be returned instead to allow recovery (accompanied by a warning).
Once the value has been successfully retrieved, the Aio is deallocated and only the value is stored in the Aio object.
Note this function operates silently and does not error even if 'aio' is not an active Aio, always returning invisibly the passed object.
s1 <- socket("pair", listen = "inproc://nanonext")
s2 <- socket("pair", dial = "inproc://nanonext")
res <- send_aio(s1, data.frame(a = 1, b = 2), timeout = 100)
res
call_aio(res)
res$result
msg <- recv_aio(s2, timeout = 100)
msg
call_aio(msg)$data
close(s1)
close(s2)
Run the code above in your browser using DataLab