diff options
author | Maxime Devos <maximedevos@telenet.be> | 2021-09-08 19:21:40 +0200 |
---|---|---|
committer | Maxime Devos <maximedevos@telenet.be> | 2021-09-21 12:21:00 +0200 |
commit | 5cfadf81bf2ac7d407e67fa9a2a2caaa7135095d (patch) | |
tree | f59feb79ffe72c653d1f4f14c35b0dc6b5b64485 /gnu | |
parent | 1b7f52b79b0c0f2f4a622f51b681af974fafd881 (diff) | |
download | gnunet-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.scm | 37 |
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?" | |||
114 | timestamp." | 114 | timestamp." |
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 | |||
121 | When connected, the thunk @var{connected} is called and estimates | ||
122 | will become available (but possibly not immediately). When a new | ||
123 | estimate is available, the procedure @var{updated} is called. This | ||
124 | procedure should accept the new estimate. When disconnected, the | ||
125 | thunk @code{disconnected} and updates will be (temporarily) unavailable, | ||
126 | until connected again. It is possible for @var{updated} to be called | ||
127 | shortly after calling @var{disconnected}. | ||
128 | |||
129 | The 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 | |||
170 | When connected, the thunk @var{connected} is called and estimates | ||
171 | will become available (but possibly not immediately). When a new | ||
172 | estimate is available, the procedure @var{updated} is called. This | ||
173 | procedure should accept the new estimate. When disconnected, the | ||
174 | thunk @code{disconnected} and updates will be (temporarily) unavailable, | ||
175 | until connected again. It is possible for @var{updated} to be called | ||
176 | shortly after calling @var{disconnected}. | ||
177 | |||
178 | The 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)))) |