Skip to content

Commit 973e7ee

Browse files
committed
clearer print method for unresolved value
1 parent f84aa32 commit 973e7ee

File tree

12 files changed

+60
-38
lines changed

12 files changed

+60
-38
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#### New Features
44

5-
* Aio values `$result`, `$raw` and `$data` now resolve without requiring `call_aio()`. Access the values directly and an NA 'unresolved value' will be returned if the Aio operation is yet to complete.
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.
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.

R/aio.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#'
3131
#' Aio values may be accessed directly at \code{$result} for a 'sendAio',
3232
#' and \code{$raw} or \code{$data} for a 'recvAio'. If the Aio operation is
33-
#' yet to complete, a logical NA 'unresolved value' will be returned. Once
33+
#' yet to complete, an 'unresolved' logical NA will be returned. Once
3434
#' completed, the resolved value will be returned instead.
3535
#'
3636
#' \code{\link{unresolved}} may also be used, which returns TRUE only if an
@@ -108,7 +108,8 @@ stop_aio <- function(aio) {
108108
#' aio <- send_aio(s1, "test", timeout = 100)
109109
#'
110110
#' while (unresolved(aio)) {
111-
#' print(unresolved(aio))
111+
#' # do stuff here before checking resolution again
112+
#' cat("unresolved")
112113
#' s2 <- socket("pair", dial = "inproc://nanonext")
113114
#' Sys.sleep(0.01)
114115
#' }

R/context.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,14 @@ reply <- function(context,
268268
#' @return A recv Aio (object of class 'recvAio').
269269
#'
270270
#' @details Sending the request and receiving the result are both performed async,
271-
#' hence the function will return immediately with a 'recvAio' object.
271+
#' hence the function will return immediately with a 'recvAio' object. Access
272+
#' the return value at \code{$data}.
272273
#'
273274
#' This is designed so that the process on the server can run concurrently
274-
#' without blocking the client. Use \code{\link{call_aio}} on the 'recvAio'
275-
#' to call the result when required.
275+
#' without blocking the client.
276+
#'
277+
#' Optionally use \code{\link{call_aio}} on the 'recvAio' to call (and wait
278+
#' for) the result.
276279
#'
277280
#' If an error occured in the server process, a nul byte \code{00} will be
278281
#' received (as \code{$data} if 'recv_mode' = 'serial', as \code{$raw}

R/nano.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ print.sendAio <- function(x, ...) {
283283
#'
284284
print.unresolvedValue <- function(x, ...) {
285285

286-
cat("< unresolved value >\n", file = stdout())
286+
cat("< unresolved: logi NA >\n", file = stdout())
287287
invisible(x)
288288

289289
}

R/sendrecv.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ send <- function(socket,
6262
#'
6363
#' @details Async send is always non-blocking and returns immediately.
6464
#'
65+
#' The send result is available at \code{$result}, which will return an
66+
#' 'unresolved' logical NA if the async operation is yet to complete.
67+
#'
6568
#' To wait for and check the result of the send operation, use
6669
#' \code{\link{call_aio}} on the returned 'sendAio' object.
6770
#'
@@ -188,8 +191,12 @@ recv <- function(socket,
188191
#'
189192
#' @details Async receive is always non-blocking and returns immediately.
190193
#'
191-
#' To wait for the AIO to complete and retrieve the received message,
192-
#' use \code{\link{call_aio}} on the returned 'recvAio' object.
194+
#' The received message is available at \code{$data}, and the raw message at
195+
#' \code{$raw} (if kept). An 'unresolved' logical NA will be returned if the
196+
#' async operation is yet to complete.
197+
#'
198+
#' To wait for the async operation to complete and retrieve the received
199+
#' message, use \code{\link{call_aio}} on the returned 'recvAio' object.
193200
#'
194201
#' Alternatively, to stop the async operation, use \code{\link{stop_aio}}.
195202
#'

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ msg$raw
208208
209209
```
210210

211-
If the async operation is yet to complete, a logical NA 'unresolved value' will be returned. In the below example an async receive is requested, but no mesages are waiting (yet to be sent).
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).
212212

213213
```{r async4}
214214

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ msg$raw
267267
#> [201] 00 fe
268268
```
269269

270-
If the async operation is yet to complete, a logical NA ‘unresolved
271-
value’ will be returned. In the below example an async receive is
272-
requested, but no mesages are waiting (yet to be sent).
270+
If the async operation is yet to complete, an ‘unresolved’ logical NA
271+
will be returned. In the below example an async receive is requested,
272+
but no mesages are waiting (yet to be sent).
273273

274274
``` r
275275
msg <- recv_aio(s2)
276276
msg$data
277-
#> < unresolved value >
277+
#> < unresolved: logi NA >
278278
```
279279

280280
For use in control flow statements, `unresolved` can be used. Note that
@@ -359,7 +359,7 @@ aio
359359
#> < recvAio >
360360
#> - $data for message data
361361
str(aio$data)
362-
#> num [1:100000000] -0.5969 0.269 0.0237 -1.1824 1.806 ...
362+
#> num [1:100000000] -0.0699 -0.0702 -0.7121 0.3036 0.1215 ...
363363
```
364364

365365
In this example the calculation is returned, but other operations may
@@ -391,38 +391,38 @@ an environment variable `NANONEXT_LOG`.
391391
``` r
392392
# set logging level to include information events ------------------------------
393393
logging(level = "info")
394-
#> 2022-03-04 09:57:23 [ log level ] set to: info
394+
#> 2022-03-04 10:37:55 [ log level ] set to: info
395395

396396
pub <- socket("pub", listen = "inproc://nanobroadcast")
397-
#> 2022-03-04 09:57:23 [ sock open ] id: 9 | protocol: pub
398-
#> 2022-03-04 09:57:23 [ list start ] sock: 9 | url: inproc://nanobroadcast
397+
#> 2022-03-04 10:37:55 [ sock open ] id: 9 | protocol: pub
398+
#> 2022-03-04 10:37:55 [ list start ] sock: 9 | url: inproc://nanobroadcast
399399
sub <- socket("sub", dial = "inproc://nanobroadcast")
400-
#> 2022-03-04 09:57:23 [ sock open ] id: 10 | protocol: sub
401-
#> 2022-03-04 09:57:23 [ dial start ] sock: 10 | url: inproc://nanobroadcast
400+
#> 2022-03-04 10:37:55 [ sock open ] id: 10 | protocol: sub
401+
#> 2022-03-04 10:37:55 [ dial start ] sock: 10 | url: inproc://nanobroadcast
402402

403403
# subscribing to a specific topic 'examples' -----------------------------------
404404
sub |> subscribe(topic = "examples")
405-
#> 2022-03-04 09:57:23 [ subscribe ] sock: 10 | topic: examples
405+
#> 2022-03-04 10:37:55 [ subscribe ] sock: 10 | topic: examples
406406
pub |> send(c("examples", "this is an example"), mode = "raw", echo = FALSE)
407407
sub |> recv(mode = "character", keep.raw = FALSE)
408408
#> [1] "examples" "this is an example"
409409

410410
pub |> send(c("other", "this other topic will not be received"), mode = "raw", echo = FALSE)
411411
sub |> recv(mode = "character", keep.raw = FALSE)
412-
#> 2022-03-04 09:57:23 [ 8 ] Try again
412+
#> 2022-03-04 10:37:55 [ 8 ] Try again
413413

414414
# specify NULL to subscribe to ALL topics --------------------------------------
415415
sub |> subscribe(topic = NULL)
416-
#> 2022-03-04 09:57:23 [ subscribe ] sock: 10 | topic: ALL
416+
#> 2022-03-04 10:37:55 [ subscribe ] sock: 10 | topic: ALL
417417
pub |> send(c("newTopic", "this is a new topic"), mode = "raw", echo = FALSE)
418418
sub |> recv("character", keep.raw = FALSE)
419419
#> [1] "newTopic" "this is a new topic"
420420

421421
sub |> unsubscribe(topic = NULL)
422-
#> 2022-03-04 09:57:23 [ unsubscribe ] sock: 10 | topic: ALL
422+
#> 2022-03-04 10:37:55 [ unsubscribe ] sock: 10 | topic: ALL
423423
pub |> send(c("newTopic", "this topic will now not be received"), mode = "raw", echo = FALSE)
424424
sub |> recv("character", keep.raw = FALSE)
425-
#> 2022-03-04 09:57:23 [ 8 ] Try again
425+
#> 2022-03-04 10:37:55 [ 8 ] Try again
426426

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

432432
# set logging level back to the default of errors only -------------------------
433433
logging(level = "error")
434-
#> 2022-03-04 09:57:23 [ log level ] set to: error
434+
#> 2022-03-04 10:37:55 [ log level ] set to: error
435435

436436
close(pub)
437437
close(sub)
@@ -477,12 +477,12 @@ res2 |> recv(keep.raw = FALSE)
477477
aio1$data
478478
#> [1] "res1"
479479
aio2$data
480-
#> < unresolved value >
480+
#> < unresolved: logi NA >
481481

482482
# after the survey expires, the second resolves into a timeout error -----------
483483
Sys.sleep(0.5)
484484
aio2$data
485-
#> 2022-03-04 09:57:24 [ 5 ] Timed out
485+
#> 2022-03-04 10:37:55 [ 5 ] Timed out
486486
#> 'errorValue' int 5
487487

488488
close(sur)
@@ -503,11 +503,11 @@ ncurl("http://httpbin.org/headers")
503503
#> [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
504504
#> [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
505505
#> [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
506-
#> [76] 2d 36 32 32 31 65 32 38 34 2d 32 30 63 63 63 36 35 30 35 31 37 35 36 37 37
507-
#> [101] 61 30 37 30 31 63 64 36 30 22 0a 20 20 7d 0a 7d 0a
506+
#> [76] 2d 36 32 32 31 65 63 30 33 2d 34 32 36 65 34 32 37 64 35 62 37 32 63 36 39
507+
#> [101] 35 31 34 31 61 31 64 32 34 22 0a 20 20 7d 0a 7d 0a
508508
#>
509509
#> $data
510-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6221e284-20ccc6505175677a0701cd60\"\n }\n}\n"
510+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6221ec03-426e427d5b72c695141a1d24\"\n }\n}\n"
511511
```
512512

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

man/call_aio.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/recv_aio.Rd

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

man/request.Rd

Lines changed: 6 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)