Learn R Programming

nanonext (version 0.5.1)

send_aio: Send Async

Description

Send data asynchronously over a connection (Socket, Context or Stream).

Usage

send_aio(con, data, mode = c("serial", "raw"), timeout = -2L)

# S3 method for nanoSocket send_aio(con, data, mode = c("serial", "raw"), timeout = -2L)

# S3 method for nanoContext send_aio(con, data, mode = c("serial", "raw"), timeout = -2L)

# S3 method for nanoStream send_aio(con, data, mode = "raw", timeout = -2L)

Arguments

con

a Socket, Context or Stream.

data

an object (a vector, if mode = 'raw').

mode

[default 'serial'] for sending serialised R objects, or 'raw' for sending vectors of any type (converted to a raw byte vector for sending). For Streams, 'raw' is the only option and any other value is ignored. Use 'serial' for perfect reproducibility within R, although 'raw' must be used when interfacing with external applications that do not understand R serialisation.

timeout

(optional) integer value in milliseconds. If unspecified, the default of -2L uses a socket-specific default, which is usually the same as no timeout.

Value

A 'sendAio' (object of class 'sendAio').

Details

Async send is always non-blocking and returns a 'sendAio' immediately.

For a 'sendAio', the send result is available at $result. An 'unresolved' logical NA is returned if the async operation is yet to complete, The resolved value will be zero on success, or else an integer error code.

To wait for and check the result of the send operation, use call_aio on the returned 'sendAio' object.

Alternatively, to stop the async operation, use stop_aio.

Examples

Run this code
# NOT RUN {
pub <- socket("pub", dial = "inproc://nanonext")

res <- send_aio(pub, data.frame(a = 1, b = 2), timeout = 100)
res
res$result

res <- send_aio(pub, "example message", mode = "raw", timeout = 100)
call_aio(res)$result

close(pub)

# }

Run the code above in your browser using DataLab