Skip to content

Commit b5cd1d7

Browse files
committed
Make connection creator non-async
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
1 parent f1c4d82 commit b5cd1d7

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

crates/factor-sqlite/src/host.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff 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

crates/factor-sqlite/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff 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]
185182
pub 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]
193189
impl<F> ConnectionCreator for F
194190
where
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
}

crates/factor-sqlite/tests/factor_test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ impl spin_factor_sqlite::DefaultLabelResolver for DefaultLabelResolver {
143143
/// A connection creator that always returns an error.
144144
struct InvalidConnectionCreator;
145145

146-
#[async_trait::async_trait]
147146
impl 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
{

crates/trigger/src/cli/sqlite_statements.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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
}))

0 commit comments

Comments
 (0)