Skip to content

Commit d14b4dc

Browse files
committed
RC4; use length instead of missing at Stream()
1 parent da18ea4 commit d14b4dc

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

R/stream.R

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,12 @@
5656
#'
5757
#' @export
5858
#'
59-
stream <- function(dial = NULL, listen = NULL, textframes = FALSE, pem = NULL) {
60-
61-
if (missing(dial)) {
62-
missing(listen) && stop("specify a URL for either 'dial' or 'listen'")
63-
.Call(rnng_stream_listen, listen, textframes, pem)
64-
} else {
65-
.Call(rnng_stream_dial, dial, textframes, pem)
66-
}
67-
68-
}
59+
stream <- function(dial = NULL, listen = NULL, textframes = FALSE, pem = NULL)
60+
if (length(dial))
61+
.Call(rnng_stream_dial, dial, textframes, pem) else
62+
if (length(listen))
63+
.Call(rnng_stream_listen, listen, textframes, pem) else
64+
stop("specify a URL for either 'dial' or 'listen'")
6965

7066
#' @rdname close
7167
#' @method close nanoStream

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ aio
365365
#> < recvAio >
366366
#> - $data for message data
367367
aio$data |> str()
368-
#> num [1:100000000] -0.177 -2.62 1.421 -1.42 -0.17 ...
368+
#> num [1:100000000] 1.312 -2.373 0.31 -0.1 0.273 ...
369369
```
370370

371371
As `call_aio()` is blocking and will wait for completion, an alternative
@@ -526,11 +526,11 @@ ncurl("https://httpbin.org/headers")
526526
#> [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
527527
#> [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
528528
#> [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
529-
#> [76] 2d 36 33 36 32 65 31 37 31 2d 35 39 63 36 39 31 61 62 34 33 63 30 33 31 36
530-
#> [101] 33 34 34 66 31 61 66 35 34 22 0a 20 20 7d 0a 7d 0a
529+
#> [76] 2d 36 33 36 32 66 64 61 31 2d 32 32 62 37 33 64 35 61 33 64 36 33 65 35 61
530+
#> [101] 62 35 39 37 38 39 61 30 61 22 0a 20 20 7d 0a 7d 0a
531531
#>
532532
#> $data
533-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6362e171-59c691ab43c0316344f1af54\"\n }\n}\n"
533+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6362fda1-22b73d5a3d63e5ab59789a0a\"\n }\n}\n"
534534
```
535535

536536
For advanced use, supports additional HTTP methods such as POST or PUT.
@@ -551,13 +551,13 @@ res
551551

552552
call_aio(res)$headers
553553
#> $Date
554-
#> [1] "Wed, 02 Nov 2022 21:30:25 GMT"
554+
#> [1] "Wed, 02 Nov 2022 23:30:41 GMT"
555555
#>
556556
#> $Server
557557
#> [1] "gunicorn/19.9.0"
558558

559559
res$data
560-
#> [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-6362e171-6bd749534693d660717763d4\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"185.225.45.49\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
560+
#> [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-6362fda1-7a5768e13ca4ff9e63c67e7f\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"185.225.45.49\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
561561
```
562562

563563
In this respect, it may be used as a performant and lightweight method
@@ -599,10 +599,10 @@ s |> send('{"action": "subscribe", "symbols": "EURUSD"}')
599599
#> [1] 0
600600

601601
s |> recv()
602-
#> [1] "{\"s\":\"EURUSD\",\"a\":0.982,\"b\":0.9817,\"dc\":\"-0.5815\",\"dd\":\"-0.0057\",\"ppms\":false,\"t\":1667424628000}"
602+
#> [1] "{\"s\":\"EURUSD\",\"a\":0.98138,\"b\":0.98126,\"dc\":\"-0.6450\",\"dd\":\"-0.0063\",\"ppms\":false,\"t\":1667431842000}"
603603

604604
s |> recv()
605-
#> [1] "{\"s\":\"EURUSD\",\"a\":0.9819,\"b\":0.9816,\"dc\":\"-0.5917\",\"dd\":\"-0.0058\",\"ppms\":false,\"t\":1667424634000}"
605+
#> [1] "{\"s\":\"EURUSD\",\"a\":0.98135,\"b\":0.98129,\"dc\":\"-0.6481\",\"dd\":\"-0.0064\",\"ppms\":false,\"t\":1667431842000}"
606606

607607
close(s)
608608
```

0 commit comments

Comments
 (0)