Skip to content

Commit 7c7d210

Browse files
committed
update docs
1 parent 973e7ee commit 7c7d210

File tree

8 files changed

+99
-70
lines changed

8 files changed

+99
-70
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Version: 0.2.0.9005
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library providing high-performance scalability protocols,
77
implementing a cross-platform standard for messaging and communications.
8-
Serves as a concurrency framework that can be used for building distributed
9-
applications.
8+
Leveraging asynchronous execution, serves as a concurrency framework for
9+
building distributed applications.
1010
Authors@R:
1111
c(person(given = "Charlie",
1212
family = "Gao",

NEWS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
#### New Features
44

5-
* Aio values `$result`, `$raw` and `$data` now resolve without requiring `call_aio()`. Access the values directly and an 'unresolved' logical NA will be returned if the Aio operation is yet to complete.
5+
* Aio values `$result`, `$data` and `$raw` now resolve without requiring `call_aio()`. Access the values directly and an 'unresolved' logical NA will be returned if the Aio operation is yet to complete.
66
* `unresolved()` added as an auxiliary function to query whether an Aio is unresolved, for use in control flow statements.
77
* Integer error values generated by receive functions are now classed 'errorValue'. `is_error_value()` helper function included.
88
* `is_nul_byte()` added as a helper function for request/reply setups.
99
* `survey_time()` added as a convenience function for surveyor/respondent patterns.
10-
* `logging()` function to specify a global package logging level - 'error' or 'info'. Automatically polls the environment variable 'NANONEXT_LOG' on package load and then each time `logging(level = "check")` is called, allowing this to be set externally.
10+
* `logging()` function to specify a global package logging level - 'error' or 'info'. Automatically checks the environment variable 'NANONEXT_LOG' on package load and then each time `logging(level = "check")` is called.
1111
* `ncurl()` adds a '...' argument. Support for HTTP methods other than GET.
1212

1313
#### Updates
1414

15+
* `listen()` and `dial()` now return (invisible) zero rather than NULL upon success for consistency with other functions.
16+
* Options documentation entry renamed to `opts` to avoid clash with base R 'options'.
1517
* Common format for NNG errors and informational events now starts with a timestamp for easier logging.
16-
* `listen()` and `dial()` now return (invisible) zero rather than NULL upon success to better align with similar functions.
1718
* Allows setting the environment variable 'NANONEXT_ARM' prior to package installation
1819
+ Fixes installation issues on certain ARM architectures
1920
* More streamlined NNG build process eliminating unused options.
20-
* Options documentation entry renamed to `opts` to avoid clash with base R 'options'.
2121
* Removes experimental `nng_timer()` utility as a non-essential function.
2222
* Deprecated functions 'send_vec' and 'recv_vec' removed.
2323

R/nanonext-package.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#'
55
#' R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is a socket
66
#' library providing high-performance scalability protocols, implementing a
7-
#' cross-platform standard for messaging and communications. Serves as a
8-
#' concurrency framework that can be used for building distributed
9-
#' applications.
7+
#' cross-platform standard for messaging and communications. Leveraging
8+
#' asynchronous execution, serves as a concurrency framework for building
9+
#' distributed applications.
1010
#'
1111
#' @section Usage notes:
1212
#'

R/utils.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ is_nul_byte <- function(x) identical(x, as.raw(0L))
6868

6969
#' Is Error Value
7070
#'
71-
#' Is the object an error value generated by NNG.
71+
#' Is the object an error value generated by NNG. All receive functions class
72+
#' integer error codes as 'errorValue' to be easily distinguishable from
73+
#' integer message values.
7274
#'
7375
#' @param x an object.
7476
#'
@@ -85,7 +87,8 @@ is_error_value <- function(x) inherits(x, "errorValue")
8587
#'
8688
.mirai_scm <- function() {
8789

88-
identical(parent.env(parent.env(parent.frame())), getNamespace("mirai")) || return(invisible())
90+
identical(parent.env(parent.env(parent.frame())), getNamespace("mirai")) ||
91+
stop("this function is for package internal use only")
8992
.Call(rnng_scm)
9093

9194
}

README.Rmd

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ knitr::opts_chunk$set(
2121
[![R-CMD-check](https://github.com/shikokuchuo/nanonext/workflows/R-CMD-check/badge.svg)](https://github.com/shikokuchuo/nanonext/actions)
2222
<!-- badges: end -->
2323

24-
R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is a socket library providing high-performance scalability protocols, implementing a cross-platform standard for messaging and communications. Serves as a concurrency framework that can be used for building distributed applications.
24+
R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is a socket library providing high-performance scalability protocols, implementing a cross-platform standard for messaging and communications. Leveraging asynchronous execution, serves as a concurrency framework for building distributed applications.
2525

2626
Designed for performance and reliability, the NNG library is written in C and {nanonext} is a lightweight wrapper depending on no other packages. Provides the interface for code and processes to communicate with each other - receive data generated in Python, perform analysis in R, and send results to a C++ program – all on the same computer or on networks spanning the globe.
2727

@@ -174,7 +174,7 @@ n$recv(mode = "double")
174174

175175
### Async and Concurrency
176176

177-
{nanonext} implements true async send and receive, leveraging NNG as a massively-scalable concurrency framework.
177+
{nanonext} implements true async send and receive, leveraging NNG as a massively-scaleable concurrency framework.
178178

179179
`send_aio()` and `recv_aio()` functions return immediately but perform their operations async.
180180

@@ -185,47 +185,52 @@ s2 <- socket("pair", dial = "inproc://nano")
185185
186186
```
187187

188-
For a 'sendAio' object, the result is stored at `$result`. An exit code of 0 denotes a successful send.
189-
190-
- send is successful as long as the message has been accepted by the socket for sending
191-
- the message may be buffered within the system
192-
- for acknowledgement of receipt, an RPC setup is required (see next section)
188+
For a 'sendAio' object, the result is stored at `$result`.
193189

194190
```{r async2}
195191
196192
res <- send_aio(s1, data.frame(a = 1, b = 2))
193+
res
197194
res$result
198195
196+
# an exit code of 0 denotes a successful send
197+
# note: the send is successful as long as the message has been accepted by the socket for sending
198+
# the message itself may still be buffered within the system
199+
199200
```
200201

201202
For a 'recvAio' object, the message is stored at `$data`, and the raw message at `$raw` (if kept).
202203

203204
```{r async3}
204205
205206
msg <- recv_aio(s2)
207+
msg
206208
msg$data
207209
msg$raw
208210
209211
```
210212

211-
If the async operation is yet to complete, an 'unresolved' logical NA will be returned. In the below example an async receive is requested, but no mesages are waiting (yet to be sent).
213+
If the async operation is yet to complete, an 'unresolved' logical NA value will be returned.
212214

213215
```{r async4}
214216
217+
# an async receive is requested, but no mesages are waiting (yet to be sent)
218+
215219
msg <- recv_aio(s2)
216220
msg$data
217221
218222
```
219223

220-
For use in control flow statements, `unresolved` can be used. Note that calling this function queries for resolution itself and may cause a previously unresolved Aio to resolve.
224+
Auxiliary function `unresolved()` can be used in control flow statements.
221225

222226
```{r async5}
223227
224-
# unresolved() already queries for resolution so no need for it again within the while clause
228+
# unresolved() queries for resolution itself so no need to use it again within the while clause
225229
226230
while (unresolved(msg)) {
227-
# do stuff here before checking resolution again
231+
# do stuff before checking resolution again
228232
send_aio(s1, "resolved")
233+
cat("unresolved")
229234
}
230235
231236
msg$data
@@ -254,7 +259,7 @@ close(s2)
254259

255260
Can be used to perform computationally-expensive calculations or I/O-bound operations such as writing large amounts of data to disk in a separate 'server' process running concurrently.
256261

257-
Server process: `reply()` will wait for a message and apply a function, in this case `rnorm()`, before sending back the result
262+
Server process: `reply()` will wait for a message and apply a function, in this case `rnorm()`, before sending back the result.
258263

259264
```{r rpcserver, eval=FALSE}
260265
@@ -294,9 +299,11 @@ str(aio$data)
294299
295300
```
296301

302+
As `call_aio()` is blocking and will wait for completion, an alternative is to query `aio$data` directly. This will return an 'unresolved' logical NA value if the calculation is yet to complete.
303+
297304
In this example the calculation is returned, but other operations may reside entirely on the server side, for example writing data to disk.
298305

299-
In such a case, using `call_aio()` confirms that the operation has completed (or it will wait for completion) and calls the return value of the function, which may typically be NULL or an exit code.
306+
In such a case, calling or querying the value confirms that the operation has completed, and provides the return value of the function, which may typically be NULL or an exit code.
300307

301308
The {mirai} package <https://shikokuchuo.net/mirai/> (available on CRAN) uses {nanonext} as the back-end to provide asynchronous execution of arbitrary R code using the RPC model.
302309

@@ -353,7 +360,7 @@ close(sub)
353360

354361
This type of pattern is useful for applications such as service discovery.
355362

356-
A surveyor sends a survey, which is broadcast to all peer respondents. The respondents then have a chance to reply (but are not obliged to). The survey itself is a timed event, such that responses received after the timeout are discarded.
363+
A surveyor sends a survey, which is broadcast to all peer respondents. Respondents are then able to reply, but are not obliged to. The survey itself is a timed event, and responses received after the timeout are discarded.
357364

358365
```{r survey}
359366
@@ -390,6 +397,8 @@ close(res2)
390397
391398
```
392399

400+
Above it can be seen that the final value resolves into a timeout, which is an integer 5 classed as 'errorValue'. All receive functions class integer error codes as 'errorValue' to be easily distinguishable from integer message values.
401+
393402
[&laquo; Back to ToC](#table-of-contents)
394403

395404
### ncurl Minimalist http Client

0 commit comments

Comments
 (0)