@@ -51,7 +51,7 @@ Implemented transports:
51515 . [ RPC and Distributed Computing] ( #rpc-and-distributed-computing )
52526 . [ Publisher / Subscriber Model] ( #publisher-subscriber-model )
53537 . [ Surveyor / Repondent Model] ( #surveyor-respondent-model )
54- 8 . [ ncurl: Minimalist http Client] ( #ncurl-minimalist -http-client )
54+ 8 . [ ncurl: (Async) HTTP Client] ( #ncurl-async -http-client )
55559 . [ stream: Websocket Client] ( #stream-websocket-client )
565610 . [ Building from source] ( #building-from-source )
575711 . [ Links] ( #links )
370370# > < recvAio >
371371# > - $data for message data
372372aio $ data | > str()
373- # > num [1:100000000] 1.079 0.855 -0.88 1.192 -0.777 ...
373+ # > num [1:100000000] 0.809 -1.518 1.473 0.943 1.033 ...
374374```
375375
376376As ` call_aio() ` is blocking and will wait for completion, an alternative
@@ -405,37 +405,37 @@ an environment variable `NANONEXT_LOG`.
405405
406406``` r
407407logging(level = " info" )
408- # > 2022-03-29 13:53:51 [ log level ] set to: info
408+ # > 2022-03-29 14:33:28 [ log level ] set to: info
409409
410410pub <- socket(" pub" , listen = " inproc://nanobroadcast" )
411- # > 2022-03-29 13:53:51 [ sock open ] id: 9 | protocol: pub
412- # > 2022-03-29 13:53:51 [ list start ] sock: 9 | url: inproc://nanobroadcast
411+ # > 2022-03-29 14:33:28 [ sock open ] id: 9 | protocol: pub
412+ # > 2022-03-29 14:33:28 [ list start ] sock: 9 | url: inproc://nanobroadcast
413413sub <- socket(" sub" , dial = " inproc://nanobroadcast" )
414- # > 2022-03-29 13:53:51 [ sock open ] id: 10 | protocol: sub
415- # > 2022-03-29 13:53:51 [ dial start ] sock: 10 | url: inproc://nanobroadcast
414+ # > 2022-03-29 14:33:28 [ sock open ] id: 10 | protocol: sub
415+ # > 2022-03-29 14:33:28 [ dial start ] sock: 10 | url: inproc://nanobroadcast
416416
417417sub | > subscribe(topic = " examples" )
418- # > 2022-03-29 13:53:51 [ subscribe ] sock: 10 | topic: examples
418+ # > 2022-03-29 14:33:28 [ subscribe ] sock: 10 | topic: examples
419419pub | > send(c(" examples" , " this is an example" ), mode = " raw" , echo = FALSE )
420420sub | > recv(mode = " character" , keep.raw = FALSE )
421421# > [1] "examples" "this is an example"
422422
423423pub | > send(c(" other" , " this other topic will not be received" ), mode = " raw" , echo = FALSE )
424424sub | > recv(mode = " character" , keep.raw = FALSE )
425- # > 2022-03-29 13:53:51 [ 8 ] Try again
425+ # > 2022-03-29 14:33:28 [ 8 ] Try again
426426
427427# specify NULL to subscribe to ALL topics
428428sub | > subscribe(topic = NULL )
429- # > 2022-03-29 13:53:51 [ subscribe ] sock: 10 | topic: ALL
429+ # > 2022-03-29 14:33:28 [ subscribe ] sock: 10 | topic: ALL
430430pub | > send(c(" newTopic" , " this is a new topic" ), mode = " raw" , echo = FALSE )
431431sub | > recv(" character" , keep.raw = FALSE )
432432# > [1] "newTopic" "this is a new topic"
433433
434434sub | > unsubscribe(topic = NULL )
435- # > 2022-03-29 13:53:51 [ unsubscribe ] sock: 10 | topic: ALL
435+ # > 2022-03-29 14:33:28 [ unsubscribe ] sock: 10 | topic: ALL
436436pub | > send(c(" newTopic" , " this topic will now not be received" ), mode = " raw" , echo = FALSE )
437437sub | > recv(" character" , keep.raw = FALSE )
438- # > 2022-03-29 13:53:51 [ 8 ] Try again
438+ # > 2022-03-29 14:33:28 [ 8 ] Try again
439439
440440# however the topics explicitly subscribed to are still received
441441pub | > send(c(" examples" , " this example will still be received" ), mode = " raw" , echo = FALSE )
@@ -444,7 +444,7 @@ sub |> recv(mode = "character", keep.raw = FALSE)
444444
445445# set logging level back to the default of errors only
446446logging(level = " error" )
447- # > 2022-03-29 13:53:51 [ log level ] set to: error
447+ # > 2022-03-29 14:33:28 [ log level ] set to: error
448448
449449close(pub )
450450close(sub )
@@ -495,7 +495,7 @@ aio2$data
495495# after the survey expires, the second resolves into a timeout error
496496Sys.sleep(0.5 )
497497aio2 $ data
498- # > 2022-03-29 13:53:52 [ 5 ] Timed out
498+ # > 2022-03-29 14:33:28 [ 5 ] Timed out
499499# > 'errorValue' int 5
500500
501501close(sur )
@@ -510,36 +510,44 @@ integer message values.
510510
511511[ « Back to ToC] ( #table-of-contents )
512512
513- ### ncurl: Minimalist http Client
513+ ### ncurl: Async HTTP Client
514514
515- ` ncurl() ` is a minimalist http(s) client. In normal use, it takes only
516- one argument, the URL. It can follow redirects.
515+ ` ncurl() ` is a minimalist http(s) client.
516+
517+ By setting ` async = TRUE ` , it performs requests asynchronously,
518+ returning immediately with a ‘recvAio’.
519+
520+ For normal use, it takes just the URL. It can follow redirects.
517521
518522``` r
519523ncurl(" http://httpbin.org/headers" )
520524# > $raw
521525# > [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
522526# > [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
523527# > [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
524- # > [76] 2d 36 32 34 33 30 31 36 30 2d 31 30 36 36 64 32 64 35 32 35 33 34 62 34 37
525- # > [101] 36 35 37 65 32 34 30 62 32 22 0a 20 20 7d 0a 7d 0a
528+ # > [76] 2d 36 32 34 33 30 61 61 38 2d 32 33 32 30 39 39 30 63 34 66 32 39 35 39 65
529+ # > [101] 66 33 38 32 63 63 34 38 62 22 0a 20 20 7d 0a 7d 0a
526530# >
527531# > $data
528- # > [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-62430160-1066d2d52534b47657e240b2 \"\n }\n}\n"
532+ # > [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-62430aa8-2320990c4f2959ef382cc48b \"\n }\n}\n"
529533```
530534
531535For advanced use, supports additional HTTP methods such as POST or PUT.
532- In this respect, it may be used as a performant and lightweight method
533- for making requests to REST APIs.
534536
535537``` r
536- res <- ncurl(" http://httpbin.org/post" , async = TRUE , " POST" , " application/json" , " Bearer APIKEY" , ' {"key": "value"}' )
538+ res <- ncurl(" http://httpbin.org/post" , async = TRUE ,
539+ " POST" , " application/json" , " Bearer APIKEY" , ' {"key": "value"}' )
540+ res
541+ # > < recvAio >
542+ # > - $data for message data
543+ # > - $raw for raw message
544+
537545call_aio(res )$ data
538- # > [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-62430160-4b8917cd2b569d8c0294f5ca \"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"79.173.189.204\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
546+ # > [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-62430aa9-733452c942d2794e22818b4e \"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"79.173.189.204\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
539547```
540548
541- There is also the option of performing requests asynchronously, in which
542- case the function returns immediately with a ‘recvAio’ .
549+ In this respect, it may be used as a performant and lightweight method
550+ for making REST API requests .
543551
544552[ « Back to ToC] ( #table-of-contents )
545553
0 commit comments