@@ -49,12 +49,13 @@ Implemented transports:
49493 . [ Cross-language Exchange] ( #cross-language-exchange )
50504 . [ Async and Concurrency] ( #async-and-concurrency )
51515 . [ Deferred Evaluation Pipe] ( #deferred-evaluation-pipe )
52- 6 . [ RPC and Distributed Computing] ( #rpc-and-distributed-computing )
53- 7 . [ Publisher / Subscriber Model] ( #publisher-subscriber-model )
54- 8 . [ Surveyor / Repondent Model] ( #surveyor-respondent-model )
55- 9 . [ ncurl Minimalist http Client] ( #ncurl-minimalist-http-client )
56- 10 . [ Building from source] ( #building-from-source )
57- 11 . [ Links] ( #links )
52+ 6 . [ Meanwhile (Concurrency) Pipe] ( #meanwhile-concurrency-pipe )
53+ 7 . [ RPC and Distributed Computing] ( #rpc-and-distributed-computing )
54+ 8 . [ Publisher / Subscriber Model] ( #publisher-subscriber-model )
55+ 9 . [ Surveyor / Repondent Model] ( #surveyor-respondent-model )
56+ 10 . [ ncurl Minimalist http Client] ( #ncurl-minimalist-http-client )
57+ 11 . [ Building from source] ( #building-from-source )
58+ 12 . [ Links] ( #links )
5859
5960### Installation
6061
@@ -344,8 +345,8 @@ The pipe operator semantics are similar to R’s base pipe `|>`:
344345` f(x) ` <br /> ` x %>>% f(y) ` is equivalent to ` f(x, y) `
345346
346347``` r
347- s1 <- socket(" pair" , listen = " inproc://cecicestunepipe " )
348- s2 <- socket(" pair" , dial = " inproc://cecicestunepipe " )
348+ s1 <- socket(" pair" , listen = " inproc://dep " )
349+ s2 <- socket(" pair" , dial = " inproc://dep " )
349350
350351# request an aysnc receive with no messages waiting
351352msg <- recv_aio(s2 )
@@ -372,6 +373,50 @@ close(s2)
372373
373374[ « Back to ToC] ( #table-of-contents )
374375
376+ ### Meanwhile (Concurrency) Pipe
377+
378+ The deferred evaluation pipe sequence may be terminated with a meanwhile
379+ (or concurrency) pipe ` %~% ` which:
380+
381+ 1 ) provides certainty of the return value, which will always be the
382+ evaluated result rather than a ‘resolvedExpr’
383+
384+ 2 ) makes it convenient to write concurrent code which runs whilst the
385+ expression is resolving
386+
387+ ` x %~% expr `
388+
389+ is equivalent to the following expression, finally returning x:
390+
391+ ` if (unresolved(x)) while (unresolved(x <- x$data)) {expr}; x `
392+
393+ Use it in the following way:
394+
395+ ``` r
396+ s1 <- socket(" pair" , listen = " inproc://meanwhile" )
397+ s2 <- socket(" pair" , dial = " inproc://meanwhile" )
398+
399+ n <- 1L
400+ rec <- recv_aio(s2 )
401+ a <- rec $ data %>> % identical(data.frame ()) %~ % {
402+ if (n == 5 ) send_aio(s1 , data.frame ())
403+ cat(" unresolved" , n , " \n " )
404+ n <- n + 1
405+ }
406+ # > unresolved 1
407+ # > unresolved 2
408+ # > unresolved 3
409+ # > unresolved 4
410+ # > unresolved 5
411+ a
412+ # > [1] TRUE
413+
414+ close(s1 )
415+ close(s2 )
416+ ```
417+
418+ [ « Back to ToC] ( #table-of-contents )
419+
375420### RPC and Distributed Computing
376421
377422{nanonext} implements remote procedure calls (RPC) using NNG’s req/rep
421466# > < recvAio >
422467# > - $data for message data
423468aio $ data | > str()
424- # > num [1:100000000] -0.82 0.147 1.761 0.425 0.182 ...
469+ # > num [1:100000000] 0.925 -0.323 1.47 -1.237 -0.555 ...
425470```
426471
427472As ` call_aio() ` is blocking and will wait for completion, an alternative
@@ -456,37 +501,37 @@ an environment variable `NANONEXT_LOG`.
456501
457502``` r
458503logging(level = " info" )
459- # > 2022-03-07 22:11:21 [ log level ] set to: info
504+ # > 2022-03-09 09:28:33 [ log level ] set to: info
460505
461506pub <- socket(" pub" , listen = " inproc://nanobroadcast" )
462- # > 2022-03-07 22:11:21 [ sock open ] id: 11 | protocol: pub
463- # > 2022-03-07 22:11:21 [ list start ] sock: 11 | url: inproc://nanobroadcast
507+ # > 2022-03-09 09:28:33 [ sock open ] id: 13 | protocol: pub
508+ # > 2022-03-09 09:28:33 [ list start ] sock: 13 | url: inproc://nanobroadcast
464509sub <- socket(" sub" , dial = " inproc://nanobroadcast" )
465- # > 2022-03-07 22:11:21 [ sock open ] id: 12 | protocol: sub
466- # > 2022-03-07 22:11:21 [ dial start ] sock: 12 | url: inproc://nanobroadcast
510+ # > 2022-03-09 09:28:33 [ sock open ] id: 14 | protocol: sub
511+ # > 2022-03-09 09:28:33 [ dial start ] sock: 14 | url: inproc://nanobroadcast
467512
468513sub | > subscribe(topic = " examples" )
469- # > 2022-03-07 22:11:21 [ subscribe ] sock: 12 | topic: examples
514+ # > 2022-03-09 09:28:33 [ subscribe ] sock: 14 | topic: examples
470515pub | > send(c(" examples" , " this is an example" ), mode = " raw" , echo = FALSE )
471516sub | > recv(mode = " character" , keep.raw = FALSE )
472517# > [1] "examples" "this is an example"
473518
474519pub | > send(c(" other" , " this other topic will not be received" ), mode = " raw" , echo = FALSE )
475520sub | > recv(mode = " character" , keep.raw = FALSE )
476- # > 2022-03-07 22:11:21 [ 8 ] Try again
521+ # > 2022-03-09 09:28:33 [ 8 ] Try again
477522
478523# specify NULL to subscribe to ALL topics
479524sub | > subscribe(topic = NULL )
480- # > 2022-03-07 22:11:21 [ subscribe ] sock: 12 | topic: ALL
525+ # > 2022-03-09 09:28:33 [ subscribe ] sock: 14 | topic: ALL
481526pub | > send(c(" newTopic" , " this is a new topic" ), mode = " raw" , echo = FALSE )
482527sub | > recv(" character" , keep.raw = FALSE )
483528# > [1] "newTopic" "this is a new topic"
484529
485530sub | > unsubscribe(topic = NULL )
486- # > 2022-03-07 22:11:21 [ unsubscribe ] sock: 12 | topic: ALL
531+ # > 2022-03-09 09:28:33 [ unsubscribe ] sock: 14 | topic: ALL
487532pub | > send(c(" newTopic" , " this topic will now not be received" ), mode = " raw" , echo = FALSE )
488533sub | > recv(" character" , keep.raw = FALSE )
489- # > 2022-03-07 22:11:21 [ 8 ] Try again
534+ # > 2022-03-09 09:28:33 [ 8 ] Try again
490535
491536# however the topics explicitly subscribed to are still received
492537pub | > send(c(" examples" , " this example will still be received" ), mode = " raw" , echo = FALSE )
@@ -495,7 +540,7 @@ sub |> recv(mode = "character", keep.raw = FALSE)
495540
496541# set logging level back to the default of errors only
497542logging(level = " error" )
498- # > 2022-03-07 22:11:21 [ log level ] set to: error
543+ # > 2022-03-09 09:28:33 [ log level ] set to: error
499544
500545close(pub )
501546close(sub )
@@ -546,7 +591,7 @@ aio2$data
546591# after the survey expires, the second resolves into a timeout error
547592Sys.sleep(0.5 )
548593aio2 $ data
549- # > 2022-03-07 22:11:22 [ 5 ] Timed out
594+ # > 2022-03-09 09:28:34 [ 5 ] Timed out
550595# > 'errorValue' int 5
551596
552597close(sur )
@@ -572,11 +617,11 @@ ncurl("http://httpbin.org/headers")
572617# > [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
573618# > [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
574619# > [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
575- # > [76] 2d 36 32 32 36 38 33 30 61 2d 33 61 62 32 30 31 39 64 35 34 64 33 66 63 66
576- # > [101] 30 32 37 30 39 66 62 62 32 22 0a 20 20 7d 0a 7d 0a
620+ # > [76] 2d 36 32 32 38 37 33 34 32 2d 31 62 36 66 35 31 39 39 30 62 65 33 61 64 38
621+ # > [101] 36 36 66 61 32 37 34 61 30 22 0a 20 20 7d 0a 7d 0a
577622# >
578623# > $data
579- # > [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6226830a-3ab2019d54d3fcf02709fbb2 \"\n }\n}\n"
624+ # > [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-62287342-1b6f51990be3ad866fa274a0 \"\n }\n}\n"
580625```
581626
582627For advanced use, supports additional HTTP methods such as POST or PUT.
0 commit comments