@@ -105,14 +105,20 @@ impl NetworkBuilder {
105
105
Ok ( self )
106
106
}
107
107
108
- /// Finalizes the initialization of the Network
108
+ /// Finalizes the initialization of the Network and returns a way to run/wait/stop the
109
+ /// FoundationDB run loop.
109
110
///
110
- /// It's not recommended to use this method unless you really know what you are doing.
111
- /// Otherwise, the `run` method is the **safe** and easiest way to do it.
111
+ /// It's not recommended to use this method directly, you probably want the `boot()` method.
112
112
///
113
- /// In order to start the network you have to call the unsafe `NetworkRunner::run()` method.
114
- /// This method starts the foundationdb network runloop, once started, the `NetworkStop::stop()`
115
- /// method **MUST** be called before the process exit. Aborting the process is still safe.
113
+ /// In order to start the network you have to:
114
+ /// - call the unsafe `NetworkRunner::run()` method, most likely in a dedicated thread
115
+ /// - wait for the thread to start `NetworkWait::wait`
116
+ ///
117
+ /// In order for the sequence to be safe, you **MUST** as stated in the `NetworkRunner::run()` method
118
+ /// ensure that `NetworkStop::stop()` is called before the process exit.
119
+ /// Aborting the process is still safe.
120
+ ///
121
+ /// # Example
116
122
///
117
123
/// ```
118
124
/// use foundationdb::api::FdbApiBuilder;
@@ -142,19 +148,25 @@ impl NetworkBuilder {
142
148
Ok ( ( NetworkRunner { cond : cond. clone ( ) } , NetworkWait { cond } ) )
143
149
}
144
150
145
- /// Initialize the FoundationDB Client API, this can only be called once per process.
151
+ /// Starts the FoundationDB run loop in a dedicated thread.
152
+ /// This finish initializing the FoundationDB Client API and can only be called once per process.
146
153
///
147
154
/// # Returns
148
155
///
149
156
/// A `NetworkAutoStop` handle which must be dropped before the program exits.
150
157
///
151
158
/// # Safety
152
159
///
160
+ /// You *MUST* ensure `drop` is called on the returned object before the program exits.
161
+ /// This is not required if the program is aborted.
162
+ ///
153
163
/// This method used to be safe in version `0.4`. But because `drop` on the returned object
154
164
/// might not be called before the program exits, it was found unsafe.
155
- /// You should prefer the safe `run` variant.
156
- /// If you still want to use this, you *MUST* ensure drop is called on the returned object
157
- /// before the program exits. This is not required if the program is aborted.
165
+ ///
166
+ /// # Panics
167
+ ///
168
+ /// Panics if the dedicated thread cannot be spawned or the internal condition primitive is
169
+ /// poisonned.
158
170
///
159
171
/// # Examples
160
172
///
@@ -194,7 +206,7 @@ impl NetworkBuilder {
194
206
195
207
/// A foundationDB network event loop runner
196
208
///
197
- /// Most of the time you should never need to use this directly and use `NetworkBuilder::run ()`.
209
+ /// Most of the time you should never need to use this directly and use `boot ()`.
198
210
pub struct NetworkRunner {
199
211
cond : Arc < ( Mutex < bool > , Condvar ) > ,
200
212
}
@@ -234,13 +246,17 @@ impl NetworkRunner {
234
246
235
247
/// A condition object that can wait for the associated `NetworkRunner` to actually run.
236
248
///
237
- /// Most of the time you should never need to use this directly and use `NetworkBuilder::run ()`.
249
+ /// Most of the time you should never need to use this directly and use `boot ()`.
238
250
pub struct NetworkWait {
239
251
cond : Arc < ( Mutex < bool > , Condvar ) > ,
240
252
}
241
253
242
254
impl NetworkWait {
243
255
/// Wait for the associated `NetworkRunner` to actually run.
256
+ ///
257
+ /// # Panics
258
+ ///
259
+ /// Panics if the internal lock cannot is poisoned
244
260
pub fn wait ( self ) -> NetworkStop {
245
261
// Wait for the thread to start up.
246
262
{
@@ -257,7 +273,7 @@ impl NetworkWait {
257
273
258
274
/// Allow to stop the associated and running `NetworkRunner`.
259
275
///
260
- /// Most of the time you should never need to use this directly and use `NetworkBuilder::run ()`.
276
+ /// Most of the time you should never need to use this directly and use `boot ()`.
261
277
pub struct NetworkStop {
262
278
_private : ( ) ,
263
279
}
@@ -270,6 +286,13 @@ impl NetworkStop {
270
286
}
271
287
272
288
/// Stop the associated `NetworkRunner` and thread if dropped
289
+ ///
290
+ /// If trying to stop the FoundationDB run loop results in an error.
291
+ /// The error is printed in `stderr` and the process aborts.
292
+ ///
293
+ /// # Panics
294
+ ///
295
+ /// Panics if the network thread cannot be joined.
273
296
pub struct NetworkAutoStop {
274
297
network : Option < NetworkStop > ,
275
298
handle : Option < std:: thread:: JoinHandle < ( ) > > ,
0 commit comments