File tree 2 files changed +16
-7
lines changed
2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -64,9 +64,12 @@ impl Connection for SqliteConnection {
64
64
65
65
fn close ( mut self ) -> BoxFuture < ' static , Result < ( ) , Error > > {
66
66
Box :: pin ( async move {
67
- self . statements . clear ( ) ;
68
- self . statement . take ( ) ;
69
- self . worker . shutdown ( ) . await
67
+ let shutdown = self . worker . shutdown ( ) ;
68
+ // Drop the statement worker and any outstanding statements, which should
69
+ // cover all references to the connection handle outside of the worker thread
70
+ drop ( self ) ;
71
+ // Ensure the worker thread has terminated
72
+ shutdown. await
70
73
} )
71
74
}
72
75
Original file line number Diff line number Diff line change @@ -140,13 +140,19 @@ impl StatementWorker {
140
140
/// A `WorkerCrashed` error may be returned if the thread has already stopped.
141
141
/// Subsequent calls to `step()`, `reset()`, or this method will fail with
142
142
/// `WorkerCrashed`. Ensure that any associated statements are dropped first.
143
- pub ( crate ) async fn shutdown ( & mut self ) -> Result < ( ) , Error > {
143
+ pub ( crate ) fn shutdown ( & mut self ) -> impl Future < Output = Result < ( ) , Error > > {
144
144
let ( tx, rx) = oneshot:: channel ( ) ;
145
145
146
- self . tx
146
+ let send_res = self
147
+ . tx
147
148
. send ( StatementWorkerCommand :: Shutdown { tx } )
148
- . map_err ( |_| Error :: WorkerCrashed ) ? ;
149
+ . map_err ( |_| Error :: WorkerCrashed ) ;
149
150
150
- rx. await . map_err ( |_| Error :: WorkerCrashed )
151
+ async move {
152
+ send_res?;
153
+
154
+ // wait for the response
155
+ rx. await . map_err ( |_| Error :: WorkerCrashed )
156
+ }
151
157
}
152
158
}
You can’t perform that action at this time.
0 commit comments