@@ -185,7 +185,7 @@ impl Row {
185
185
type CallFn = Box < dyn FnOnce ( & mut rusqlite:: Connection ) + Send + ' static > ;
186
186
187
187
enum Message {
188
- Execute ( CallFn ) ,
188
+ Run ( CallFn ) ,
189
189
Close ( oneshot:: Sender < std:: result:: Result < ( ) , rusqlite:: Error > > ) ,
190
190
}
191
191
@@ -224,7 +224,7 @@ impl Connection {
224
224
225
225
self
226
226
. sender
227
- . send ( Message :: Execute ( Box :: new ( move |conn| {
227
+ . send ( Message :: Run ( Box :: new ( move |conn| {
228
228
let value = function ( conn) ;
229
229
let _ = sender. send ( value) ;
230
230
} ) ) )
@@ -239,41 +239,14 @@ impl Connection {
239
239
{
240
240
self
241
241
. sender
242
- . send ( Message :: Execute ( Box :: new ( move |conn| {
242
+ . send ( Message :: Run ( Box :: new ( move |conn| {
243
243
function ( conn) ;
244
244
} ) ) )
245
245
. map_err ( |_| Error :: ConnectionClosed ) ?;
246
246
247
247
return Ok ( ( ) ) ;
248
248
}
249
249
250
- /// Call a function in background thread and get the result
251
- /// asynchronously.
252
- ///
253
- /// This method can cause a `panic` if the underlying database connection is closed.
254
- /// it is a more user-friendly alternative to the [`Connection::call`] method.
255
- /// It should be safe if the connection is never explicitly closed (using the
256
- /// [`Connection::close`] call).
257
- ///
258
- /// Calling this on a closed connection will cause a `panic`.
259
- pub async fn call_unwrap < F , R > ( & self , function : F ) -> R
260
- where
261
- F : FnOnce ( & mut rusqlite:: Connection ) -> R + Send + ' static ,
262
- R : Send + ' static ,
263
- {
264
- let ( sender, receiver) = oneshot:: channel :: < R > ( ) ;
265
-
266
- self
267
- . sender
268
- . send ( Message :: Execute ( Box :: new ( move |conn| {
269
- let value = function ( conn) ;
270
- let _ = sender. send ( value) ;
271
- } ) ) )
272
- . expect ( "database connection should be open" ) ;
273
-
274
- receiver. await . expect ( BUG_TEXT )
275
- }
276
-
277
250
/// Query SQL statement.
278
251
pub async fn query ( & self , sql : & str , params : impl Params + Send + ' static ) -> Result < Rows > {
279
252
let sql = sql. to_string ( ) ;
@@ -464,20 +437,14 @@ where
464
437
fn event_loop ( mut conn : rusqlite:: Connection , receiver : Receiver < Message > ) {
465
438
while let Ok ( message) = receiver. recv ( ) {
466
439
match message {
467
- Message :: Execute ( f) => f ( & mut conn) ,
440
+ Message :: Run ( f) => f ( & mut conn) ,
468
441
Message :: Close ( s) => {
469
- let result = conn. close ( ) ;
442
+ match conn. close ( ) {
443
+ Ok ( v) => s. send ( Ok ( v) ) . expect ( BUG_TEXT ) ,
444
+ Err ( ( _conn, e) ) => s. send ( Err ( e) ) . expect ( BUG_TEXT ) ,
445
+ } ;
470
446
471
- match result {
472
- Ok ( v) => {
473
- s. send ( Ok ( v) ) . expect ( BUG_TEXT ) ;
474
- break ;
475
- }
476
- Err ( ( c, e) ) => {
477
- conn = c;
478
- s. send ( Err ( e) ) . expect ( BUG_TEXT ) ;
479
- }
480
- }
447
+ return ;
481
448
}
482
449
}
483
450
}
0 commit comments