Skip to content

Commit fbe9d0e

Browse files
committed
CRAN release 0.8.1
1 parent 2dc3ff2 commit fbe9d0e

22 files changed

+144
-76
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Package: nanonext
22
Type: Package
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 0.8.0.9001
4+
Version: 0.8.1
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library providing high-performance scalability protocols, a
77
cross-platform standard for messaging and communications. Serves as a
88
concurrency framework for building distributed applications, utilising 'aio'
99
objects which resolve automatically upon completion of asynchronous
1010
operations. Implements synchronisation primitives, allowing R to wait upon
11-
socket events or message receives being signalled by concurrent threads.
11+
events being signalled by concurrent messaging threads.
1212
Authors@R:
1313
c(person(given = "Charlie",
1414
family = "Gao",

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ S3method(print,unresolvedValue)
3535
S3method(start,nanoDialer)
3636
S3method(start,nanoListener)
3737
export("opt<-")
38+
export("weakref<-")
3839
export(.unresolved)
3940
export(base64dec)
4041
export(base64enc)

NEWS.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
# nanonext 0.8.0.9001 (development)
1+
# nanonext 0.8.1
22

33
#### New Features
44

55
* Implements synchronisation primitives from the NNG library. Condition variables allow the R execution thread to wait until it is signalled by an incoming message or pipe event.
66
+ adds core functions `cv()`, `wait()`, `until()`, `cv_value()`, and `cv_reset()`.
77
+ adds signalling receive functions `recv_aio_signal()` and `request_signal()`.
88
+ `pipe_notify()` signals up to 2 condition variables whenever pipes are added or removed at a socket.
9-
* Implements `msg_pipe()` to return the pipe connection associated with a 'recvAio' message.
9+
* Adds `msg_pipe()` to return the pipe connection associated with a 'recvAio' message.
1010
* Exposes the `sha1()` cryptographic hash and HMAC generation function from the 'Mbed TLS' library (for secure applications, use one of the SHA-2 algorithms instead).
11+
* Utility function `'weakref<-'()` exposes `R_MakeWeakRef` from R's C API. Useful for keeping objects alive for as long as required by a dependent object.
1112

1213
#### Updates
1314

15+
* `ncurl_session()` gains a 'timeout' argument, and returns an 'errorValue' with warning upon error.
1416
* `listen()` and `dial()` gain the new logical argument 'error' to govern the function behaviour upon error.
15-
* `.unresolved()` is introduced as a technical utility (not recommended for general use) that just queries the status of an Aio without attempting to retrieve the result or message.
1617
* Internal performance enhancements.
1718

1819
# nanonext 0.8.0

R/aio.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ recv_aio <- function(con,
131131
#' should be signalled when the async receive is complete.
132132
#'
133133
#' @details \strong{For the signalling version}: when the receive is complete,
134-
#' the supplied 'conditionVariable' is signalled by incrementing it by 1.
135-
#' This happens asynchronously and independently of the main R execution
134+
#' the supplied 'conditionVariable' is signalled by incrementing its value
135+
#' by 1. This happens asynchronously and independently of the R execution
136136
#' thread.
137137
#'
138138
#' @examples
@@ -282,10 +282,11 @@ unresolved <- function(aio) .Call(rnng_unresolved, aio)
282282

283283
#' Technical Utility: Query if an Aio is Unresolved
284284
#'
285-
#' Query whether an Aio remains unresolved. This function is a technical utility
286-
#' version of \code{\link{unresolved}} not intended for ordinary use.
287-
#' Provides a method of querying the busy status of an Aio without altering
288-
#' its state in any way i.e. not attempting to retrieve the result or message.
285+
#' Query whether an Aio remains unresolved. This function is an experimental
286+
#' technical utility version of \code{\link{unresolved}} not intended for
287+
#' ordinary use. Provides a method of querying the busy status of an Aio
288+
#' without altering its state in any way i.e. not attempting to retrieve the
289+
#' result or message.
289290
#'
290291
#' @param aio an Aio (object of class 'sendAio' or 'recvAio').
291292
#'

R/context.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ reply <- function(context,
151151
#'
152152
#' Implements a caller/client for the req node of the req/rep protocol. Sends
153153
#' data to the rep node (executor/server) and returns an Aio, which can be
154-
#' called when the result is required.
154+
#' called for the value when required.
155155
#'
156156
#' @inheritParams reply
157157
#' @inheritParams recv
@@ -212,8 +212,8 @@ request <- function(context,
212212
#' @inheritParams recv_aio_signal
213213
#'
214214
#' @details \strong{For the signalling version}: when the receive is complete,
215-
#' the supplied 'conditionVariable' is signalled by incrementing it by 1.
216-
#' This happens asynchronously and independently of the main R execution
215+
#' the supplied 'conditionVariable' is signalled by incrementing its value
216+
#' by 1. This happens asynchronously and independently of the R execution
217217
#' thread.
218218
#'
219219
#' @examples

R/nanonext-package.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
#' concurrency framework for building distributed applications, utilising
2525
#' 'aio' objects which resolve automatically upon completion of asynchronous
2626
#' operations. Implements synchronisation primitives, allowing R to wait
27-
#' upon socket events or message receives being signalled by concurrent
28-
#' threads.
27+
#' upon events being signalled by concurrent messaging threads.
2928
#'
3029
#' @section Usage notes:
3130
#'

R/ncurl.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,17 @@ ncurl <- function(url,
9090
#' once over the connection.
9191
#'
9292
#' @inheritParams ncurl
93+
#' @param timeout (optional) integer value in milliseconds after which the
94+
#' connection and subsequent transact attempts time out.
9395
#'
94-
#' @return For \code{ncurl_session}: an 'ncurlSession' object.
96+
#' @return For \code{ncurl_session}: an 'ncurlSession' object if successful, or
97+
#' else an 'errorValue'.
9598
#'
9699
#' @examples
97-
#' s <- tryCatch(ncurl_session("https://httpbin.org/get", response = "date"), error = identity)
100+
#' s <- ncurl_session("https://httpbin.org/get", response = "date", timeout = 1000L)
98101
#' s
99-
#' if (!inherits(s, "error")) transact(s)
100-
#' if (!inherits(s, "error")) close(s)
102+
#' if (!is_error_value(s)) transact(s)
103+
#' if (!is_error_value(s)) close(s)
101104
#'
102105
#' @export
103106
#'
@@ -107,8 +110,9 @@ ncurl_session <- function(url,
107110
headers = NULL,
108111
data = NULL,
109112
response = NULL,
113+
timeout = NULL,
110114
pem = NULL)
111-
.Call(rnng_ncurl_session, url, convert, method, headers, data, response, pem)
115+
.Call(rnng_ncurl_session, url, convert, method, headers, data, response, timeout, pem)
112116

113117
#' @param session an 'ncurlSession' object.
114118
#'

R/utils.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,22 @@ is_nul_byte <- function(x) .Call(rnng_is_nul_byte, x)
262262
#'
263263
status_code <- function(x) .Call(rnng_status_code, x)
264264

265+
#' Make Weak Reference
266+
#'
267+
#' Exposes R's C API function \code{R_MakeWeakRef}, for registering a 'value' to
268+
#' a 'key' as a weak reference. The object 'value' is kept alive as long as
269+
#' 'key' remains reachable.
270+
#'
271+
#' @param key a reference object i.e. an environment or external pointer.
272+
#' @param value an object.
273+
#'
274+
#' @return 'key' (with 'value' registered as a weak reference).
275+
#'
276+
#' @details If 'value' is an external pointer, an appropriate finaliser for
277+
#' 'value' should be registered separately, as this function does not
278+
#' register any finalisers to be run when 'key' becomes unreachable.
279+
#'
280+
#' @export
281+
#'
282+
`weakref<-` <- function(key, value) .Call(rnng_make_weakref, key, value)
283+

README.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ knitr::opts_chunk$set(
2222
[![codecov](https://codecov.io/gh/shikokuchuo/nanonext/branch/main/graph/badge.svg)](https://app.codecov.io/gh/shikokuchuo/nanonext)
2323
<!-- badges: end -->
2424

25-
R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is a socket library providing high-performance scalability protocols, a cross-platform standard for messaging and communications. Serves as a concurrency framework for building distributed applications, utilising 'aio' objects which resolve automatically upon completion of asynchronous operations. Implements synchronisation primitives, allowing R to wait upon socket events or message receives being signalled by concurrent threads.
25+
R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is a socket library providing high-performance scalability protocols, a cross-platform standard for messaging and communications. Serves as a concurrency framework for building distributed applications, utilising 'aio' objects which resolve automatically upon completion of asynchronous operations. Implements synchronisation primitives, allowing R to wait upon events being signalled by concurrent messaging threads.
2626

2727
Designed for performance and reliability, the NNG library is written in C and {nanonext} is a lightweight zero-dependency wrapper. 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.
2828

@@ -320,7 +320,7 @@ The {crew} package <https://wlandau.github.io/crew/> (available on CRAN) by Will
320320

321321
### Synchronisation Primitives
322322

323-
{nanonext} exposes synchronisation primitives implemented in the NNG library, available for cross-platform use.
323+
{nanonext} implements synchronisation primitives provided by the NNG library for cross-platform use.
324324

325325
As the R interpreter runs on a single thread, synchronisation primitives such as mutexes and condition variables are not natively implemented in the R language. However, as NNG is inherently threaded and messaging can be asynchronous, it is possible to synchronise between NNG events happening independently and the main R execution thread.
326326

README.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ cross-platform standard for messaging and communications. Serves as a
1919
concurrency framework for building distributed applications, utilising
2020
‘aio’ objects which resolve automatically upon completion of
2121
asynchronous operations. Implements synchronisation primitives, allowing
22-
R to wait upon socket events or message receives being signalled by
23-
concurrent threads.
22+
R to wait upon events being signalled by concurrent messaging threads.
2423

2524
Designed for performance and reliability, the NNG library is written in
2625
C and {nanonext} is a lightweight zero-dependency wrapper. Provides the
@@ -369,7 +368,7 @@ aio
369368
#> < recvAio >
370369
#> - $data for message data
371370
aio$data |> str()
372-
#> num [1:100000000] -0.3184 -0.5206 0.0942 -0.7144 0.1338 ...
371+
#> num [1:100000000] 1.0595 0.0664 0.1575 0.9746 -0.3545 ...
373372
```
374373

375374
As `call_aio()` is blocking and will wait for completion, an alternative
@@ -395,8 +394,8 @@ platforms for distributed workers.
395394

396395
### Synchronisation Primitives
397396

398-
{nanonext} exposes synchronisation primitives implemented in the NNG
399-
library, available for cross-platform use.
397+
{nanonext} implements synchronisation primitives provided by the NNG
398+
library for cross-platform use.
400399

401400
As the R interpreter runs on a single thread, synchronisation primitives
402401
such as mutexes and condition variables are not natively implemented in
@@ -653,11 +652,11 @@ ncurl("https://httpbin.org/headers")
653652
#> [1] 7b 0a 20 20 22 68 65 61 64 65 72 73 22 3a 20 7b 0a 20 20 20 20 22 48 6f 73
654653
#> [26] 74 22 3a 20 22 68 74 74 70 62 69 6e 2e 6f 72 67 22 2c 20 0a 20 20 20 20 22
655654
#> [51] 58 2d 41 6d 7a 6e 2d 54 72 61 63 65 2d 49 64 22 3a 20 22 52 6f 6f 74 3d 31
656-
#> [76] 2d 36 34 31 64 39 66 33 63 2d 32 37 65 35 66 36 32 31 32 33 66 63 66 33 61
657-
#> [101] 63 33 66 64 65 31 65 32 33 22 0a 20 20 7d 0a 7d 0a
655+
#> [76] 2d 36 34 32 31 35 65 66 39 2d 31 34 39 35 31 65 66 39 35 64 65 37 64 65 34
656+
#> [101] 64 34 35 35 36 30 63 39 35 22 0a 20 20 7d 0a 7d 0a
658657
#>
659658
#> $data
660-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-641d9f3c-27e5f62123fcf3ac3fde1e23\"\n }\n}\n"
659+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-64215ef9-14951ef95de7de4d45560c95\"\n }\n}\n"
661660
```
662661

663662
For advanced use, supports additional HTTP methods such as POST or PUT.
@@ -678,13 +677,13 @@ res
678677

679678
call_aio(res)$headers
680679
#> $Date
681-
#> [1] "Fri, 24 Mar 2023 13:01:48 GMT"
680+
#> [1] "Mon, 27 Mar 2023 09:16:41 GMT"
682681
#>
683682
#> $Server
684683
#> [1] "gunicorn/19.9.0"
685684

686685
res$data
687-
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-641d9f3c-0e871ca3155cd46f0e923b0a\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"131.111.5.14\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
686+
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-64215ef9-781527dd121d916b1a92a377\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"131.111.5.14\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
688687
```
689688

690689
In this respect, it may be used as a performant and lightweight method
@@ -710,7 +709,7 @@ transact(sess)
710709
#>
711710
#> $headers
712711
#> $headers$date
713-
#> [1] "Fri, 24 Mar 2023 13:01:49 GMT"
712+
#> [1] "Mon, 27 Mar 2023 09:16:42 GMT"
714713
#>
715714
#>
716715
#> $raw
@@ -720,15 +719,15 @@ transact(sess)
720719
#> [76] 22 43 6f 6e 74 65 6e 74 2d 54 79 70 65 22 3a 20 22 61 70 70 6c 69 63 61 74
721720
#> [101] 69 6f 6e 2f 6a 73 6f 6e 22 2c 20 0a 20 20 20 20 22 48 6f 73 74 22 3a 20 22
722721
#> [126] 68 74 74 70 62 69 6e 2e 6f 72 67 22 2c 20 0a 20 20 20 20 22 58 2d 41 6d 7a
723-
#> [151] 6e 2d 54 72 61 63 65 2d 49 64 22 3a 20 22 52 6f 6f 74 3d 31 2d 36 34 31 64
724-
#> [176] 39 66 33 64 2d 36 30 61 63 36 35 35 30 30 37 37 34 39 66 33 34 34 31 34 34
725-
#> [201] 34 64 66 62 22 0a 20 20 7d 2c 20 0a 20 20 22 6f 72 69 67 69 6e 22 3a 20 22
726-
#> [226] 37 39 2e 31 37 33 2e 31 32 39 2e 32 22 2c 20 0a 20 20 22 75 72 6c 22 3a 20
727-
#> [251] 22 68 74 74 70 73 3a 2f 2f 68 74 74 70 62 69 6e 2e 6f 72 67 2f 67 65 74 22
728-
#> [276] 0a 7d 0a
722+
#> [151] 6e 2d 54 72 61 63 65 2d 49 64 22 3a 20 22 52 6f 6f 74 3d 31 2d 36 34 32 31
723+
#> [176] 35 65 66 61 2d 32 35 32 65 37 39 65 31 31 39 39 38 62 38 66 61 36 63 30 66
724+
#> [201] 61 33 66 33 22 0a 20 20 7d 2c 20 0a 20 20 22 6f 72 69 67 69 6e 22 3a 20 22
725+
#> [226] 32 31 33 2e 38 36 2e 31 36 39 2e 33 34 22 2c 20 0a 20 20 22 75 72 6c 22 3a
726+
#> [251] 20 22 68 74 74 70 73 3a 2f 2f 68 74 74 70 62 69 6e 2e 6f 72 67 2f 67 65 74
727+
#> [276] 22 0a 7d 0a
729728
#>
730729
#> $data
731-
#> [1] "{\n \"args\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-641d9f3d-60ac655007749f3441444dfb\"\n }, \n \"origin\": \"131.111.5.14\", \n \"url\": \"https://httpbin.org/get\"\n}\n"
730+
#> [1] "{\n \"args\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-64215efa-252e79e11998b8fa6c0fa3f3\"\n }, \n \"origin\": \"131.111.5.14\", \n \"url\": \"https://httpbin.org/get\"\n}\n"
732731
```
733732

734733
[« Back to ToC](#table-of-contents)

0 commit comments

Comments
 (0)