Retrieve the value of an asynchronous AIO operation, waiting for the AIO operation to complete if still in progress.

call_aio(aio)

Arguments

aio

An Aio (object of class 'sendAio' or 'recvAio').

Value

The passed object (invisibly).

Details

For a 'recvAio', the received raw vector may be retrieved at $raw (unless 'keep.raw' was set to FALSE when receiving), and the converted R object 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', in case of an error in unserialisation or data conversion (for example if the incorrect mode was specified), the received raw vector will be stored at $data to allow for the data to be recovered.

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.

Alternatively

Aio values may be accessed directly at $result for a 'sendAio', and $raw or $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.

Examples

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
#> < sendAio >
#>  - $result for send result
call_aio(res)
res$result
#> [1] 0

msg <- recv_aio(s2, timeout = 100)
msg
#> < recvAio >
#>  - $data for message data
#>  - $raw for raw message
call_aio(msg)$data
#>   a b
#> 1 1 2

close(s1)
close(s2)