Learn R Programming

nanonext (version 0.5.4)

call_aio: Call the Value of an Asynchronous AIO Operation

Description

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

Usage

call_aio(aio)

Value

The passed object (invisibly).

Arguments

aio

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

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.

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.

Examples

Run this code
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