File tree Expand file tree Collapse file tree 4 files changed +10
-19
lines changed Expand file tree Collapse file tree 4 files changed +10
-19
lines changed Original file line number Diff line number Diff line change @@ -66,15 +66,12 @@ impl v2::HostConnection for InstanceState {
6666 if !self . allowed_databases . contains ( & database) {
6767 return Err ( v2:: Error :: AccessDenied ) ;
6868 }
69- ( self . get_connection_creator ) ( & database)
69+ let conn = ( self . get_connection_creator ) ( & database)
7070 . ok_or ( v2:: Error :: NoSuchDatabase ) ?
71- . create_connection ( )
72- . await
73- . and_then ( |conn| {
74- self . connections
75- . push ( conn)
76- . map_err ( |( ) | v2:: Error :: Io ( "too many connections opened" . to_string ( ) ) )
77- } )
71+ . create_connection ( ) ?;
72+ self . connections
73+ . push ( conn)
74+ . map_err ( |( ) | v2:: Error :: Io ( "too many connections opened" . to_string ( ) ) )
7875 . map ( Resource :: new_own)
7976 }
8077
Original file line number Diff line number Diff line change @@ -173,28 +173,24 @@ impl AppState {
173173 & self ,
174174 label : & str ,
175175 ) -> Option < Result < Box < dyn Connection > , v2:: Error > > {
176- let connection = ( self . get_connection_creator ) ( label) ?
177- . create_connection ( )
178- . await ;
176+ let connection = ( self . get_connection_creator ) ( label) ?. create_connection ( ) ;
179177 Some ( connection)
180178 }
181179}
182180
183181/// A creator of a connections for a particular SQLite database.
184- #[ async_trait]
185182pub trait ConnectionCreator : Send + Sync {
186183 /// Get a *new* [`Connection`]
187184 ///
188185 /// The connection should be a new connection, not a reused one.
189- async fn create_connection ( & self ) -> Result < Box < dyn Connection + ' static > , v2:: Error > ;
186+ fn create_connection ( & self ) -> Result < Box < dyn Connection + ' static > , v2:: Error > ;
190187}
191188
192- #[ async_trait:: async_trait]
193189impl < F > ConnectionCreator for F
194190where
195191 F : Fn ( ) -> anyhow:: Result < Box < dyn Connection + ' static > > + Send + Sync + ' static ,
196192{
197- async fn create_connection ( & self ) -> Result < Box < dyn Connection + ' static > , v2:: Error > {
193+ fn create_connection ( & self ) -> Result < Box < dyn Connection + ' static > , v2:: Error > {
198194 ( self ) ( ) . map_err ( |_| v2:: Error :: InvalidConnection )
199195 }
200196}
Original file line number Diff line number Diff line change @@ -143,9 +143,8 @@ impl spin_factor_sqlite::DefaultLabelResolver for DefaultLabelResolver {
143143/// A connection creator that always returns an error.
144144struct InvalidConnectionCreator ;
145145
146- #[ async_trait:: async_trait]
147146impl spin_factor_sqlite:: ConnectionCreator for InvalidConnectionCreator {
148- async fn create_connection (
147+ fn create_connection (
149148 & self ,
150149 ) -> Result < Box < dyn spin_factor_sqlite:: Connection + ' static > , spin_world:: v2:: sqlite:: Error >
151150 {
Original file line number Diff line number Diff line change @@ -177,9 +177,8 @@ mod tests {
177177 }
178178 }
179179
180- #[ async_trait]
181180 impl ConnectionCreator for MockCreator {
182- async fn create_connection ( & self ) -> Result < Box < dyn Connection + ' static > , v2:: Error > {
181+ fn create_connection ( & self ) -> Result < Box < dyn Connection + ' static > , v2:: Error > {
183182 Ok ( Box :: new ( MockConnection {
184183 tx : self . tx . clone ( ) ,
185184 } ) )
You can’t perform that action at this time.
0 commit comments