Skip to content

Commit 2d21925

Browse files
committed
implements lazy loading of later package
1 parent 156c8f8 commit 2d21925

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+584
-523
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: nanonext
22
Type: Package
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 0.13.6.9016
4+
Version: 0.13.6.9017
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library implementing 'Scalability Protocols', a reliable,
77
high-performance standard for common communications patterns including

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export(until_)
9797
export(wait)
9898
export(wait_)
9999
export(write_cert)
100-
importFrom(later,run_now)
101100
importFrom(stats,start)
102101
importFrom(tools,md5sum)
103102
importFrom(utils,.DollarNames)

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# nanonext 0.13.6.9016 (development)
1+
# nanonext 0.13.6.9017 (development)
22

33
#### New Features
44

55
* Integrates with the `later` package to provide the foundation for truly event-driven (non-polling) promises (thanks @jcheng5 for the initial prototype in #28), where side-effects are enacted asynchronously upon aio completion.
66
+ `request()` and `request_signal()` modified internally to support conversion of 'recvAio' to event-driven promises.
77
+ adds dependency on the `later` package to ensure asynchronous R code is always run on the main R thread.
8+
+ `later` is lazily loaded the first time a promise is used, and does not impact performance otherwise.
89

910
#### Updates
1011

R/aio.R

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626
#' @param timeout [default NULL] integer value in milliseconds or NULL, which
2727
#' applies a socket-specific default, usually the same as no timeout.
2828
#'
29-
#' @return A 'sendAio' (object of class 'sendAio') (invisibly).
29+
#' @return A \sQuote{sendAio} (object of class \sQuote{sendAio}) (invisibly).
3030
#'
31-
#' @details Async send is always non-blocking and returns a 'sendAio'
31+
#' @details Async send is always non-blocking and returns a \sQuote{sendAio}
3232
#' immediately.
3333
#'
34-
#' For a 'sendAio', the send result is available at \code{$result}. An
35-
#' 'unresolved' logical NA is returned if the async operation is yet to
36-
#' complete. The resolved value will be zero on success, or else an integer
37-
#' error code.
34+
#' For a \sQuote{sendAio}, the send result is available at \code{$result}.
35+
#' An \sQuote{unresolved} logical NA is returned if the async operation is
36+
#' yet to complete. The resolved value will be zero on success, or else an
37+
#' integer error code.
3838
#'
3939
#' To wait for and check the result of the send operation, use
40-
#' \code{\link{call_aio}} on the returned 'sendAio' object.
40+
#' \code{\link{call_aio}} on the returned \sQuote{sendAio} object.
4141
#'
4242
#' Alternatively, to stop the async operation, use \code{\link{stop_aio}}.
4343
#'
@@ -67,21 +67,22 @@ send_aio <- function(con, data, mode = c("serial", "raw", "next"), timeout = NUL
6767
#' @inheritParams recv
6868
#' @inheritParams send_aio
6969
#'
70-
#' @return A 'recvAio' (object of class 'recvAio') (invisibly).
70+
#' @return A \sQuote{recvAio} (object of class \sQuote{recvAio}) (invisibly).
7171
#'
72-
#' @details Async receive is always non-blocking and returns a 'recvAio'
72+
#' @details Async receive is always non-blocking and returns a \sQuote{recvAio}
7373
#' immediately.
7474
#'
75-
#' For a 'recvAio', the received message is available at \code{$data}. An
76-
#' 'unresolved' logical NA is returned if the async operation is yet to
77-
#' complete.
75+
#' For a \sQuote{recvAio}, the received message is available at \code{$data}.
76+
#' An \sQuote{unresolved} logical NA is returned if the async operation is
77+
#' yet to complete.
7878
#'
7979
#' To wait for the async operation to complete and retrieve the received
80-
#' message, use \code{\link{call_aio}} on the returned 'recvAio' object.
80+
#' message, use \code{\link{call_aio}} on the returned \sQuote{recvAio}
81+
#' object.
8182
#'
8283
#' Alternatively, to stop the async operation, use \code{\link{stop_aio}}.
8384
#'
84-
#' In case of an error, an integer 'errorValue' is returned (to be
85+
#' In case of an error, an integer \sQuote{errorValue} is returned (to be
8586
#' distiguishable from an integer message value). This can be checked using
8687
#' \code{\link{is_error_value}}.
8788
#'
@@ -122,16 +123,16 @@ recv_aio <- function(con,
122123

123124
#' Receive Async and Signal a Condition
124125
#'
125-
#' A signalling version of the function takes a 'conditionVariable' as an
126+
#' A signalling version of the function takes a \sQuote{conditionVariable} as an
126127
#' additional argument and signals it when the async receive is complete.
127128
#'
128-
#' @param cv \strong{For the signalling version}: a 'conditionVariable' to
129-
#' signal when the async receive is complete.
129+
#' @param cv \strong{For the signalling version}: a \sQuote{conditionVariable}
130+
#' to signal when the async receive is complete.
130131
#'
131132
#' @details \strong{For the signalling version}: when the receive is complete,
132-
#' the supplied 'conditionVariable' is signalled by incrementing its value
133-
#' by 1. This happens asynchronously and independently of the R execution
134-
#' thread.
133+
#' the supplied \sQuote{conditionVariable} is signalled by incrementing its
134+
#' value by 1. This happens asynchronously and independently of the R
135+
#' execution thread.
135136
#'
136137
#' @examples
137138
#' # Signalling a condition variable
@@ -166,34 +167,38 @@ recv_aio_signal <- function(con,
166167
#' \code{call_aio} retrieves the value of an asynchronous Aio operation, waiting
167168
#' for the operation to complete if still in progress.
168169
#'
169-
#' @param aio an Aio (object of class 'sendAio', 'recvAio' or 'ncurlAio').
170+
#' @param aio an Aio (object of class \sQuote{sendAio}, \sQuote{recvAio} or
171+
#' \sQuote{ncurlAio}).
170172
#'
171173
#' @return The passed object (invisibly).
172174
#'
173-
#' @details For a 'recvAio', the received value may be retrieved at \code{$data}.
175+
#' @details For a \sQuote{recvAio}, the received value may be retrieved at
176+
#' \code{$data}.
174177
#'
175-
#' For a 'sendAio', the send result may be retrieved at \code{$result}. This
176-
#' will be zero on success, or else an integer error code.
178+
#' For a \sQuote{sendAio}, the send result may be retrieved at
179+
#' \code{$result}. This will be zero on success, or else an integer error
180+
#' code.
177181
#'
178-
#' To access the values directly, use for example on a 'recvAio' \code{x}:
179-
#' \code{call_aio(x)$data}.
182+
#' To access the values directly, use for example on a \sQuote{recvAio}
183+
#' \code{x}: \code{call_aio(x)$data}.
180184
#'
181-
#' For a 'recvAio', if an error occurred in unserialization or conversion of
182-
#' the message data to the specified mode, a raw vector will be returned
183-
#' instead to allow recovery (accompanied by a warning).
185+
#' For a \sQuote{recvAio}, if an error occurred in unserialization or
186+
#' conversion of the message data to the specified mode, a raw vector will
187+
#' be returned instead to allow recovery (accompanied by a warning).
184188
#'
185189
#' Once the value has been successfully retrieved, the Aio is deallocated
186190
#' and only the value is stored in the Aio object.
187191
#'
188-
#' Note this function operates silently and does not error even if 'aio' is
189-
#' not an active Aio, always returning invisibly the passed object.
192+
#' Note this function operates silently and does not error even if
193+
#' \sQuote{aio} is not an active Aio, always returning invisibly the passed
194+
#' object.
190195
#'
191196
#' @section Alternatively:
192197
#'
193-
#' Aio values may be accessed directly at \code{$result} for a 'sendAio',
194-
#' and \code{$data} for a 'recvAio'. If the Aio operation is yet to complete,
195-
#' an 'unresolved' logical NA will be returned. Once complete, the resolved
196-
#' value will be returned instead.
198+
#' Aio values may be accessed directly at \code{$result} for a
199+
#' \sQuote{sendAio}, and \code{$data} for a \sQuote{recvAio}. If the Aio
200+
#' operation is yet to complete, an \sQuote{unresolved} logical NA will be
201+
#' returned. Once complete, the resolved value will be returned instead.
197202
#'
198203
#' \code{\link{unresolved}} may also be used, which returns TRUE only if an
199204
#' Aio or Aio value has yet to resolve and FALSE otherwise. This is suitable
@@ -237,14 +242,14 @@ call_aio_ <- function(aio) invisible(.Call(rnng_wait_thread_create, aio))
237242
#'
238243
#' @return Invisible NULL.
239244
#'
240-
#' @details Stops the asynchronous I/O operation associated with 'aio' by
245+
#' @details Stops the asynchronous I/O operation associated with \sQuote{aio} by
241246
#' aborting, and then waits for it to complete or to be completely aborted,
242-
#' and for the callback associated with the 'aio' to have completed
243-
#' executing. If successful, the 'aio' will resolve to an 'errorValue' 20
244-
#' (Operation canceled).
247+
#' and for the callback associated with the \sQuote{aio} to have completed
248+
#' executing. If successful, the \sQuote{aio} will resolve to an
249+
#' \sQuote{errorValue} 20 (Operation canceled).
245250
#'
246-
#' Note this function operates silently and does not error even if 'aio' is
247-
#' not an active Aio, always returning invisible NULL.
251+
#' Note this function operates silently and does not error even if
252+
#' \sQuote{aio} is not an active Aio, always returning invisible NULL.
248253
#'
249254
#' @export
250255
#'
@@ -255,16 +260,17 @@ stop_aio <- function(aio) invisible(.Call(rnng_aio_stop, aio))
255260
#' Query whether an Aio or Aio value remains unresolved. Unlike
256261
#' \code{\link{call_aio}}, this function does not wait for completion.
257262
#'
258-
#' @param aio an Aio (object of class 'sendAio' or 'recvAio'), or Aio value
259-
#' stored in \code{$result} or \code{$data} as the case may be.
263+
#' @param aio an Aio (object of class \sQuote{sendAio} or \sQuote{recvAio}), or
264+
#' Aio value stored in \code{$result} or \code{$data} as the case may be.
260265
#'
261-
#' @return Logical TRUE if 'aio' is an unresolved Aio or Aio value, or FALSE
262-
#' otherwise.
266+
#' @return Logical TRUE if \sQuote{aio} is an unresolved Aio or Aio value, or
267+
#' FALSE otherwise.
263268
#'
264269
#' @details Suitable for use in control flow statements such as \code{while} or
265270
#' \code{if}.
266271
#'
267-
#' Note: querying resolution may cause a previously unresolved Aio to resolve.
272+
#' Note: querying resolution may cause a previously unresolved Aio to
273+
#' resolve.
268274
#'
269275
#' @examples
270276
#' s1 <- socket("pair", listen = "inproc://nanonext")
@@ -292,11 +298,11 @@ unresolved <- function(aio) .Call(rnng_unresolved, aio)
292298
#' altering its state in any way i.e. not attempting to retrieve the result
293299
#' or message.
294300
#'
295-
#' @param aio an Aio (object of class 'sendAio' or 'recvAio').
301+
#' @param aio an Aio (object of class \sQuote{sendAio} or \sQuote{recvAio}).
296302
#'
297-
#' @return Logical TRUE if 'aio' is an unresolved Aio, or FALSE otherwise.
303+
#' @return Logical TRUE if \sQuote{aio} is an unresolved Aio, or FALSE otherwise.
298304
#'
299-
#' @details \code{.unresolved()} is not intended to be used for 'recvAio'
305+
#' @details \code{.unresolved()} is not intended to be used for \sQuote{recvAio}
300306
#' returned by a signalling function, in which case \code{\link{unresolved}}
301307
#' must be used in all cases.
302308
#'

R/context.R

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#'
2525
#' @param socket a Socket.
2626
#'
27-
#' @return A Context (object of class 'nanoContext' and 'nano').
27+
#' @return A Context (object of class \sQuote{nanoContext} and \sQuote{nano}).
2828
#'
2929
#' @details Contexts allow the independent and concurrent use of stateful
3030
#' operations using the same socket. For example, two different contexts
@@ -101,17 +101,18 @@ close.nanoContext <- function(con, ...) invisible(.Call(rnng_ctx_close, con))
101101
#' @param execute a function which takes the received (converted) data as its
102102
#' first argument. Can be an anonymous function of the form
103103
#' \code{function(x) do(x)}. Additional arguments can also be passed in
104-
#' through '...'.
104+
#' through \sQuote{...}.
105105
#' @param send_mode [default 'serial'] character value or integer equivalent -
106-
#' one of 'serial' (1L) to send serialised R objects, 'raw' (2L) to send
107-
#' atomic vectors of any type as a raw byte vector, or 'next' (3L) - see
108-
#' 'Send Modes' section below.
106+
#' one of \sQuote{serial} (1L) to send serialised R objects, \sQuote{raw}
107+
#' (2L) to send atomic vectors of any type as a raw byte vector, or
108+
#' \sQuote{next} (3L) - see \sQuote{Send Modes} section below.
109109
#' @param recv_mode [default 'serial'] character value or integer equivalent -
110-
#' one of 'serial' (1L), 'character' (2L), 'complex' (3L), 'double' (4L),
111-
#' 'integer' (5L), 'logical' (6L), 'numeric' (7L), 'raw' (8L), or 'string'
112-
#' (9L). The default 'serial' means a serialised R object; for the other
113-
#' modes, received bytes are converted into the respective mode. 'string' is
114-
#' a faster option for length one character vectors.
110+
#' one of \sQuote{serial} (1L), \sQuote{character} (2L), \sQuote{complex}
111+
#' (3L), \sQuote{double} (4L), \sQuote{integer} (5L), \sQuote{logical} (6L),
112+
#' \sQuote{numeric} (7L), \sQuote{raw} (8L), or \sQuote{string} (9L). The
113+
#' default \sQuote{serial} means a serialised R object; for the other
114+
#' modes, received bytes are converted into the respective mode.
115+
#' \sQuote{string} is a faster option for length one character vectors.
115116
#' @param timeout [default NULL] integer value in milliseconds or NULL, which
116117
#' applies a socket-specific default, usually the same as no timeout. Note
117118
#' that this applies to receiving the request. The total elapsed time would
@@ -180,21 +181,21 @@ reply <- function(context,
180181
#'
181182
#' @inheritParams reply
182183
#' @inheritParams recv
183-
#' @param data an object (if send_mode = 'raw', a vector).
184+
#' @param data an object (if send_mode = \sQuote{raw}, a vector).
184185
#' @param timeout [default NULL] integer value in milliseconds or NULL, which
185186
#' applies a socket-specific default, usually the same as no timeout.
186187
#'
187-
#' @return A 'recvAio' (object of class 'recvAio') (invisibly).
188+
#' @return A \sQuote{recvAio} (object of class \sQuote{recvAio}) (invisibly).
188189
#'
189190
#' @details Sending the request and receiving the result are both performed
190-
#' async, hence the function will return immediately with a 'recvAio'
191+
#' async, hence the function will return immediately with a \sQuote{recvAio}
191192
#' object. Access the return value at \code{$data}.
192193
#'
193194
#' This is designed so that the process on the server can run concurrently
194195
#' without blocking the client.
195196
#'
196-
#' Optionally use \code{\link{call_aio}} on the 'recvAio' to call (and wait
197-
#' for) the result.
197+
#' Optionally use \code{\link{call_aio}} on the \sQuote{recvAio} to call
198+
#' (and wait for) the result.
198199
#'
199200
#' If an error occured in the server process, a nul byte \code{00} will be
200201
#' received. This allows an error to be easily distinguished from a NULL
@@ -203,8 +204,8 @@ reply <- function(context,
203204
#'
204205
#' It is recommended to use a new context for each request to ensure
205206
#' consistent state tracking. For safety, the context used for the request
206-
#' is closed when all references to the returned 'recvAio' are removed and
207-
#' the object is garbage collected.
207+
#' is closed when all references to the returned \sQuote{recvAio} are
208+
#' removed and the object is garbage collected.
208209
#'
209210
#' @inheritSection send Send Modes
210211
#'
@@ -232,15 +233,15 @@ request <- function(context,
232233

233234
#' Request and Signal a Condition Variable (RPC Client for Req/Rep Protocol)
234235
#'
235-
#' A signalling version of the function takes a 'conditionVariable' as an
236+
#' A signalling version of the function takes a \sQuote{conditionVariable} as an
236237
#' additional argument and signals it when the async receive is complete.
237238
#'
238239
#' @inheritParams recv_aio_signal
239240
#'
240241
#' @details \strong{For the signalling version}: when the receive is complete,
241-
#' the supplied 'conditionVariable' is signalled by incrementing its value
242-
#' by 1. This happens asynchronously and independently of the R execution
243-
#' thread.
242+
#' the supplied \sQuote{conditionVariable} is signalled by incrementing its
243+
#' value by 1. This happens asynchronously and independently of the R
244+
#' execution thread.
244245
#'
245246
#' @examples
246247
#' # Signalling a condition variable
@@ -279,11 +280,11 @@ request_signal <- function(context,
279280
#' \code{\link{request_signal}}.
280281
#' @param ctx the context environment.
281282
#'
282-
#' @details The object passed as 'x' is returned regardless of whether the
283-
#' promise context was set successfully or not. If successful, 'x' is
284-
#' modified in place with the promise context.
283+
#' @details The object passed as \sQuote{x} is returned regardless of whether
284+
#' the promise context was set successfully or not. If successful,
285+
#' \sQuote{x} is modified in place with the promise context.
285286
#'
286-
#' @return The object 'x'.
287+
#' @return The object \sQuote{x}.
287288
#'
288289
#' @keywords internal
289290
#' @export

R/listdial.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
#' @param tls [default NULL] for secure tls+tcp:// or wss:// connections only,
2828
#' provide a TLS configuration object created by \code{\link{tls_config}}.
2929
#' @param autostart [default TRUE] whether to start the dialer (by default
30-
#' asynchronously). Set to NA to start synchronously - this is less resilient
31-
#' if a connection is not immediately possible, but avoids subtle errors
32-
#' from attempting to use the socket before an asynchronous dial has completed.
33-
#' Set to FALSE if setting configuration options on the dialer as it is not
34-
#' generally possible to change these once started.
30+
#' asynchronously). Set to NA to start synchronously - this is less
31+
#' resilient if a connection is not immediately possible, but avoids subtle
32+
#' errors from attempting to use the socket before an asynchronous dial has
33+
#' completed. Set to FALSE if setting configuration options on the dialer as
34+
#' it is not generally possible to change these once started.
3535
#' @param error [default FALSE] behaviour on error: if FALSE, returns an integer
3636
#' exit code accompanied by a warning, or, if TRUE, generates an error and
3737
#' halts execution.
3838
#'
3939
#' @return Invisibly, an integer exit code (zero on success). A new Dialer
40-
#' (object of class 'nanoDialer' and 'nano') is created and bound to the
41-
#' Socket if successful.
40+
#' (object of class \sQuote{nanoDialer} and \sQuote{nano}) is created and
41+
#' bound to the Socket if successful.
4242
#'
4343
#' @details To view all Dialers bound to a socket use \code{$dialer} on the
4444
#' socket, which returns a list of Dialer objects. To access any individual
@@ -100,12 +100,12 @@ dial <- function(socket, url = "inproc://nanonext", tls = NULL, autostart = TRUE
100100
#' possible to change these once started.
101101
#'
102102
#' @return Invisibly, an integer exit code (zero on success). A new Listener
103-
#' (object of class 'nanoListener' and 'nano') is created and bound to the
104-
#' Socket if successful.
103+
#' (object of class \sQuote{nanoListener} and \sQuote{nano}) is created and
104+
#' bound to the Socket if successful.
105105
#'
106106
#' @details To view all Listeners bound to a socket use \code{$listener} on the
107-
#' socket, which returns a list of Listener objects. To access any individual
108-
#' Listener (e.g. to set options on it), index into the list e.g.
107+
#' socket, which returns a list of Listener objects. To access any
108+
#' individual Listener (e.g. to set options on it), index into the list e.g.
109109
#' \code{$listener[[1]]} to return the first Listener.
110110
#'
111111
#' A listener is an external pointer to a listener object, which accepts

R/messenger.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
#'
4646
#' \code{:q} is the command to quit.
4747
#'
48-
#' Both parties must supply the same argument for 'auth', otherwise the
49-
#' party trying to connect will receive an 'authentication error' and be
50-
#' disconnected immediately.
48+
#' Both parties must supply the same argument for \sQuote{auth}, otherwise
49+
#' the party trying to connect will receive an \sQuote{authentication error}
50+
#' and be immediately disconnected.
5151
#'
5252
#' @export
5353
#'

R/nano.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#'
2424
#' @inheritParams socket
2525
#'
26-
#' @return A nano object of class 'nanoObject'.
26+
#' @return A nano object of class \sQuote{nanoObject}.
2727
#'
2828
#' @details This function encapsulates a Socket, Dialer and/or Listener, and its
2929
#' associated methods.

0 commit comments

Comments
 (0)