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 {
66
66
if !self . allowed_databases . contains ( & database) {
67
67
return Err ( v2:: Error :: AccessDenied ) ;
68
68
}
69
- ( self . get_connection_creator ) ( & database)
69
+ let conn = ( self . get_connection_creator ) ( & database)
70
70
. 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 ( ) ) )
78
75
. map ( Resource :: new_own)
79
76
}
80
77
Original file line number Diff line number Diff line change @@ -173,28 +173,24 @@ impl AppState {
173
173
& self ,
174
174
label : & str ,
175
175
) -> 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 ( ) ;
179
177
Some ( connection)
180
178
}
181
179
}
182
180
183
181
/// A creator of a connections for a particular SQLite database.
184
- #[ async_trait]
185
182
pub trait ConnectionCreator : Send + Sync {
186
183
/// Get a *new* [`Connection`]
187
184
///
188
185
/// 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 > ;
190
187
}
191
188
192
- #[ async_trait:: async_trait]
193
189
impl < F > ConnectionCreator for F
194
190
where
195
191
F : Fn ( ) -> anyhow:: Result < Box < dyn Connection + ' static > > + Send + Sync + ' static ,
196
192
{
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 > {
198
194
( self ) ( ) . map_err ( |_| v2:: Error :: InvalidConnection )
199
195
}
200
196
}
Original file line number Diff line number Diff line change @@ -143,9 +143,8 @@ impl spin_factor_sqlite::DefaultLabelResolver for DefaultLabelResolver {
143
143
/// A connection creator that always returns an error.
144
144
struct InvalidConnectionCreator ;
145
145
146
- #[ async_trait:: async_trait]
147
146
impl spin_factor_sqlite:: ConnectionCreator for InvalidConnectionCreator {
148
- async fn create_connection (
147
+ fn create_connection (
149
148
& self ,
150
149
) -> Result < Box < dyn spin_factor_sqlite:: Connection + ' static > , spin_world:: v2:: sqlite:: Error >
151
150
{
Original file line number Diff line number Diff line change @@ -177,9 +177,8 @@ mod tests {
177
177
}
178
178
}
179
179
180
- #[ async_trait]
181
180
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 > {
183
182
Ok ( Box :: new ( MockConnection {
184
183
tx : self . tx . clone ( ) ,
185
184
} ) )
You can’t perform that action at this time.
0 commit comments