Skip to content

Commit 4a70216

Browse files
committed
update DESCRIPTION
1 parent e41f602 commit 4a70216

File tree

5 files changed

+77
-63
lines changed

5 files changed

+77
-63
lines changed

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ 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-
Leveraging asynchronous execution, serves as a concurrency framework for
9-
building distributed applications.
8+
Serves as a concurrency framework for building distributed applications,
9+
utilising 'Aio' objects which return an unresolved value whilst its
10+
asynchronous operation is ongoing, automatically resolving to a final value
11+
once complete.
1012
Authors@R:
1113
c(person(given = "Charlie",
1214
family = "Gao",

R/nanonext-package.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
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. Leveraging
8-
#' asynchronous execution, serves as a concurrency framework for building
9-
#' distributed applications.
7+
#' cross-platform standard for messaging and communications. Serves as a
8+
#' concurrency framework for building distributed applications, utilising
9+
#' 'Aio' objects which return an unresolved value whilst its asynchronous
10+
#' operation is ongoing, automatically resolving to a final value once
11+
#' complete.
1012
#'
1113
#' @section Usage notes:
1214
#'

README.Rmd

Lines changed: 19 additions & 17 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. Leveraging asynchronous execution, serves as a concurrency framework 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. Serves as a concurrency framework for building distributed applications, utilising 'Aio' objects which return an unresolved value whilst its asynchronous operation is ongoing, automatically resolving to a final value once complete.
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

@@ -176,15 +176,26 @@ n$recv(mode = "double")
176176

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

179-
`send_aio()` and `recv_aio()` functions return immediately but perform their operations async.
180-
181179
```{r async}
182180
library(nanonext)
183181
s1 <- socket("pair", listen = "inproc://nano")
184182
s2 <- socket("pair", dial = "inproc://nano")
185183
186184
```
187185

186+
`send_aio()` and `recv_aio()` functions return immediately with an 'Aio' object, but perform their operations async.
187+
188+
An 'Aio' object returns an unresolved value whilst its asynchronous operation is ongoing, automatically resolving to a final value once complete.
189+
190+
```{r async4}
191+
192+
# an async receive is requested, but no mesages are waiting (yet to be sent)
193+
msg <- recv_aio(s2)
194+
msg
195+
msg$data
196+
197+
```
198+
188199
For a 'sendAio' object, the result is stored at `$result`.
189200

190201
```{r async2}
@@ -203,36 +214,26 @@ For a 'recvAio' object, the message is stored at `$data`, and the raw message at
203214

204215
```{r async3}
205216
206-
msg <- recv_aio(s2)
207-
msg
217+
# now that a message has been sent, the 'recvAio' automatically resolves
208218
msg$data
209219
msg$raw
210220
211221
```
212222

213-
If the async operation is yet to complete, an 'unresolved' logical NA value will be returned.
214-
215-
```{r async4}
223+
Auxiliary function `unresolved()` may be used in control flow statements to perform actions which depend on resolution of the Aio, both before and after. This means there is no need to actually wait (block) for an Aio to resolve, as the example below demonstrates.
216224

217-
# an async receive is requested, but no mesages are waiting (yet to be sent)
225+
```{r async5}
218226
219227
msg <- recv_aio(s2)
220-
msg$data
221-
222-
```
223-
224-
Auxiliary function `unresolved()` can be used in control flow statements.
225-
226-
```{r async5}
227228
228229
# unresolved() queries for resolution itself so no need to use it again within the while clause
229-
230230
while (unresolved(msg)) {
231231
# do stuff before checking resolution again
232232
send_aio(s1, "resolved")
233233
cat("unresolved")
234234
}
235235
236+
# perform actions which depend on the Aio value outside the while loop
236237
msg$data
237238
```
238239

@@ -282,6 +283,7 @@ aio <- request(ctxq, data = 1e8, recv_mode = "double", keep.raw = FALSE)
282283
```
283284

284285
At this point, the client can run additional code concurrent with the server processing the request.
286+
285287
```{r rpcclient2}
286288
# do more...
287289
```

README.md

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ badge](https://shikokuchuo.r-universe.dev/badges/nanonext?color=3f72af)](https:/
1515
R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is a
1616
socket library providing high-performance scalability protocols,
1717
implementing a cross-platform standard for messaging and communications.
18-
Leveraging asynchronous execution, serves as a concurrency framework for
19-
building distributed applications.
18+
Serves as a concurrency framework for building distributed applications,
19+
utilising ‘Aio’ objects which return an unresolved value whilst its
20+
asynchronous operation is ongoing, automatically resolving to a final
21+
value once complete.
2022

2123
Designed for performance and reliability, the NNG library is written in
2224
C and {nanonext} is a lightweight wrapper depending on no other
@@ -223,15 +225,30 @@ n$recv(mode = "double")
223225
{nanonext} implements true async send and receive, leveraging NNG as a
224226
massively-scaleable concurrency framework.
225227

226-
`send_aio()` and `recv_aio()` functions return immediately but perform
227-
their operations async.
228-
229228
``` r
230229
library(nanonext)
231230
s1 <- socket("pair", listen = "inproc://nano")
232231
s2 <- socket("pair", dial = "inproc://nano")
233232
```
234233

234+
`send_aio()` and `recv_aio()` functions return immediately with an ‘Aio’
235+
object, but perform their operations async.
236+
237+
An ‘Aio’ object returns an unresolved value whilst its asynchronous
238+
operation is ongoing, automatically resolving to a final value once
239+
complete.
240+
241+
``` r
242+
# an async receive is requested, but no mesages are waiting (yet to be sent)
243+
msg <- recv_aio(s2)
244+
msg
245+
#> < recvAio >
246+
#> - $data for message data
247+
#> - $raw for raw message
248+
msg$data
249+
#> < unresolved: logi NA >
250+
```
251+
235252
For a ‘sendAio’ object, the result is stored at `$result`.
236253

237254
``` r
@@ -251,11 +268,7 @@ For a ‘recvAio’ object, the message is stored at `$data`, and the raw
251268
message at `$raw` (if kept).
252269

253270
``` r
254-
msg <- recv_aio(s2)
255-
msg
256-
#> < recvAio >
257-
#> - $data for message data
258-
#> - $raw for raw message
271+
# now that a message has been sent, the 'recvAio' automatically resolves
259272
msg$data
260273
#> a b
261274
#> 1 1 2
@@ -271,30 +284,23 @@ msg$raw
271284
#> [201] 00 fe
272285
```
273286

274-
If the async operation is yet to complete, an ‘unresolved’ logical NA
275-
value will be returned.
287+
Auxiliary function `unresolved()` may be used in control flow statements
288+
to perform actions which depend on resolution of the Aio, both before
289+
and after. This means there is no need to actually wait (block) for an
290+
Aio to resolve, as the example below demonstrates.
276291

277292
``` r
278-
# an async receive is requested, but no mesages are waiting (yet to be sent)
279-
280293
msg <- recv_aio(s2)
281-
msg$data
282-
#> < unresolved: logi NA >
283-
```
284294

285-
Auxiliary function `unresolved()` can be used in control flow
286-
statements.
287-
288-
``` r
289295
# unresolved() queries for resolution itself so no need to use it again within the while clause
290-
291296
while (unresolved(msg)) {
292297
# do stuff before checking resolution again
293298
send_aio(s1, "resolved")
294299
cat("unresolved")
295300
}
296301
#> unresolved
297302

303+
# perform actions which depend on the Aio value outside the while loop
298304
msg$data
299305
#> [1] "resolved"
300306
```
@@ -365,7 +371,7 @@ aio
365371
#> < recvAio >
366372
#> - $data for message data
367373
str(aio$data)
368-
#> num [1:100000000] 1.0964 0.2245 -0.0617 -1.2121 -0.2527 ...
374+
#> num [1:100000000] -0.0948 0.4204 0.031 1.9219 -0.23 ...
369375
```
370376

371377
As `call_aio()` is blocking and will wait for completion, an alternative
@@ -400,37 +406,37 @@ an environment variable `NANONEXT_LOG`.
400406

401407
``` r
402408
logging(level = "info")
403-
#> 2022-03-04 23:52:52 [ log level ] set to: info
409+
#> 2022-03-05 14:09:43 [ log level ] set to: info
404410

405411
pub <- socket("pub", listen = "inproc://nanobroadcast")
406-
#> 2022-03-04 23:52:52 [ sock open ] id: 9 | protocol: pub
407-
#> 2022-03-04 23:52:52 [ list start ] sock: 9 | url: inproc://nanobroadcast
412+
#> 2022-03-05 14:09:43 [ sock open ] id: 9 | protocol: pub
413+
#> 2022-03-05 14:09:43 [ list start ] sock: 9 | url: inproc://nanobroadcast
408414
sub <- socket("sub", dial = "inproc://nanobroadcast")
409-
#> 2022-03-04 23:52:52 [ sock open ] id: 10 | protocol: sub
410-
#> 2022-03-04 23:52:52 [ dial start ] sock: 10 | url: inproc://nanobroadcast
415+
#> 2022-03-05 14:09:43 [ sock open ] id: 10 | protocol: sub
416+
#> 2022-03-05 14:09:43 [ dial start ] sock: 10 | url: inproc://nanobroadcast
411417

412418
sub |> subscribe(topic = "examples")
413-
#> 2022-03-04 23:52:52 [ subscribe ] sock: 10 | topic: examples
419+
#> 2022-03-05 14:09:43 [ subscribe ] sock: 10 | topic: examples
414420
pub |> send(c("examples", "this is an example"), mode = "raw", echo = FALSE)
415421
sub |> recv(mode = "character", keep.raw = FALSE)
416422
#> [1] "examples" "this is an example"
417423

418424
pub |> send(c("other", "this other topic will not be received"), mode = "raw", echo = FALSE)
419425
sub |> recv(mode = "character", keep.raw = FALSE)
420-
#> 2022-03-04 23:52:52 [ 8 ] Try again
426+
#> 2022-03-05 14:09:43 [ 8 ] Try again
421427

422428
# specify NULL to subscribe to ALL topics
423429
sub |> subscribe(topic = NULL)
424-
#> 2022-03-04 23:52:52 [ subscribe ] sock: 10 | topic: ALL
430+
#> 2022-03-05 14:09:43 [ subscribe ] sock: 10 | topic: ALL
425431
pub |> send(c("newTopic", "this is a new topic"), mode = "raw", echo = FALSE)
426432
sub |> recv("character", keep.raw = FALSE)
427433
#> [1] "newTopic" "this is a new topic"
428434

429435
sub |> unsubscribe(topic = NULL)
430-
#> 2022-03-04 23:52:52 [ unsubscribe ] sock: 10 | topic: ALL
436+
#> 2022-03-05 14:09:43 [ unsubscribe ] sock: 10 | topic: ALL
431437
pub |> send(c("newTopic", "this topic will now not be received"), mode = "raw", echo = FALSE)
432438
sub |> recv("character", keep.raw = FALSE)
433-
#> 2022-03-04 23:52:52 [ 8 ] Try again
439+
#> 2022-03-05 14:09:43 [ 8 ] Try again
434440

435441
# however the topics explicitly subscribed to are still received
436442
pub |> send(c("examples", "this example will still be received"), mode = "raw", echo = FALSE)
@@ -439,7 +445,7 @@ sub |> recv(mode = "character", keep.raw = FALSE)
439445

440446
# set logging level back to the default of errors only
441447
logging(level = "error")
442-
#> 2022-03-04 23:52:52 [ log level ] set to: error
448+
#> 2022-03-05 14:09:43 [ log level ] set to: error
443449

444450
close(pub)
445451
close(sub)
@@ -490,7 +496,7 @@ aio2$data
490496
# after the survey expires, the second resolves into a timeout error
491497
Sys.sleep(0.5)
492498
aio2$data
493-
#> 2022-03-04 23:52:53 [ 5 ] Timed out
499+
#> 2022-03-05 14:09:44 [ 5 ] Timed out
494500
#> 'errorValue' int 5
495501

496502
close(sur)
@@ -516,11 +522,11 @@ ncurl("http://httpbin.org/headers")
516522
#> [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
517523
#> [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
518524
#> [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
519-
#> [76] 2d 36 32 32 32 61 36 35 35 2d 33 31 31 32 32 33 61 39 35 35 37 35 62 36 31
520-
#> [101] 39 33 66 36 61 63 63 65 64 22 0a 20 20 7d 0a 7d 0a
525+
#> [76] 2d 36 32 32 33 36 66 32 38 2d 31 62 61 30 35 65 31 63 36 34 66 63 63 63 31
526+
#> [101] 39 34 65 32 37 33 62 62 38 22 0a 20 20 7d 0a 7d 0a
521527
#>
522528
#> $data
523-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6222a655-311223a95575b6193f6acced\"\n }\n}\n"
529+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-62236f28-1ba05e1c64fccc194e273bb8\"\n }\n}\n"
524530
```
525531

526532
For advanced use, supports additional HTTP methods such as POST or PUT.

man/nanonext-package.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)