aboutsummaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorMaxime Devos <maximedevos@telenet.be>2021-09-08 19:21:40 +0200
committerMaxime Devos <maximedevos@telenet.be>2021-09-21 12:21:00 +0200
commit5cfadf81bf2ac7d407e67fa9a2a2caaa7135095d (patch)
treef59feb79ffe72c653d1f4f14c35b0dc6b5b64485 /gnu
parent1b7f52b79b0c0f2f4a622f51b681af974fafd881 (diff)
downloadgnunet-scheme-5cfadf81bf2ac7d407e67fa9a2a2caaa7135095d.tar.gz
gnunet-scheme-5cfadf81bf2ac7d407e67fa9a2a2caaa7135095d.zip
nse/client: Prepare for auto-reconnecting.
* gnu/gnunet/nse/client.scm (reconnect): Extract from ... (connect): ... here.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/gnunet/nse/client.scm37
1 files changed, 21 insertions, 16 deletions
diff --git a/gnu/gnunet/nse/client.scm b/gnu/gnunet/nse/client.scm
index 4420d23..a9072ef 100644
--- a/gnu/gnunet/nse/client.scm
+++ b/gnu/gnunet/nse/client.scm
@@ -35,7 +35,7 @@
35 ;; TODO: disconnect 35 ;; TODO: disconnect
36 estimate) 36 estimate)
37 (import (only (rnrs base) 37 (import (only (rnrs base)
38 begin define quote lambda case values expt = else) 38 begin define quote lambda case values expt = else apply)
39 (only (rnrs control) 39 (only (rnrs control)
40 when) 40 when)
41 (only (rnrs records syntactic) 41 (only (rnrs records syntactic)
@@ -114,20 +114,9 @@ Maybe +inf.0 as well?"
114timestamp." 114timestamp."
115 (%estimate:timestamp estimate)) 115 (%estimate:timestamp estimate))
116 116
117 (define* (connect config #:key updated connected disconnected 117 ;; See 'connect'.
118 (spawn spawn-fiber)) 118 (define* (reconnect estimate/box config #:key updated connected disconnected
119 "Connect to the NSE service in the background. 119 (spawn spawn-fiber))
120
121When connected, the thunk @var{connected} is called and estimates
122will become available (but possibly not immediately). When a new
123estimate is available, the procedure @var{updated} is called. This
124procedure should accept the new estimate. When disconnected, the
125thunk @code{disconnected} and updates will be (temporarily) unavailable,
126until connected again. It is possible for @var{updated} to be called
127shortly after calling @var{disconnected}.
128
129The procedures @var{updated}, @var{connected} and @var{disconnected} are optional."
130 (define estimate/box (make-atomic-box #f))
131 (define (handle-estimate! estimate-slice) 120 (define (handle-estimate! estimate-slice)
132 (define estimate 121 (define estimate
133 (%make-estimate 122 (%make-estimate
@@ -172,5 +161,21 @@ The procedures @var{updated}, @var{connected} and @var{disconnected} are optiona
172 (values)))) 161 (values))))
173 (define mq (connect/fibers config "nse" handlers error-handler 162 (define mq (connect/fibers config "nse" handlers error-handler
174 #:spawn spawn)) 163 #:spawn spawn))
175 (signal-condition! mq-defined) 164 (signal-condition! mq-defined))
165
166 (define* (connect config #:key updated connected disconnected
167 (spawn spawn-fiber) #:rest rest)
168 "Connect to the NSE service in the background.
169
170When connected, the thunk @var{connected} is called and estimates
171will become available (but possibly not immediately). When a new
172estimate is available, the procedure @var{updated} is called. This
173procedure should accept the new estimate. When disconnected, the
174thunk @code{disconnected} and updates will be (temporarily) unavailable,
175until connected again. It is possible for @var{updated} to be called
176shortly after calling @var{disconnected}.
177
178The procedures @var{updated}, @var{connected} and @var{disconnected} are optional."
179 (define estimate/box (make-atomic-box #f))
180 (apply reconnect estimate/box config rest)
176 (%make-server estimate/box)))) 181 (%make-server estimate/box))))