Learn R Programming

nanonext (version 0.1.0)

ctx_recv_vec: Receive Vector over Context (Async)

Description

Receive vector data asynchronously over a Context (with ability to set a timeout). The counterpart to ctx_send_vec, data will be re-created from the raw vector according to the specified mode. Can be used when interfacing with external programs.

Usage

ctx_recv_vec(
  context,
  mode = c("character", "complex", "double", "integer", "logical", "numeric", "raw"),
  n = 1L,
  timeout,
  keep.raw = TRUE
)

Arguments

context

a Context.

mode

[default 'character'] mode of vector to be read - one of 'character', 'complex', 'double', 'integer', 'logical', 'numeric', 'raw'.

n

[default 1L] number of messages to receive asynchronously.

timeout

in ms. If unspecified, a socket-specific default timeout will be used.

keep.raw

[default TRUE] TRUE to keep the received raw vector (useful for verification e.g. via hashing). If FALSE, will return the unserialised object only.

Value

Named list of 2 elements: 'raw' containing a list of received raw vectors and 'data' containing a list of vectors decoded to the type 'mode', or else a list of vectors decoded to type 'mode' if keep.raw is set to FALSE.

Note: a list of lists is always returned even when n = 1. To access the first raw element, for example, use $raw[[1]] and the first data element use $data[[1]].

Details

Async recv will block while awaiting all 'n' messages to arrive. Set a timeout to ensure that the function returns under all conditions.

Examples

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

ctxq <- context(req)
ctxp <- context(rep)
ctx_send_vec(ctxq, c(1.1, 2.2), c(3.3, 4.4), timeout = 100)
ctx_recv_vec(ctxp, "double", 2L, timeout = 100)

close(req)
close(rep)

# }

Run the code above in your browser using DataLab