Skip to content

Commit 9c67cd4

Browse files
authored
Creating a Graph doesn't have to be async (#219)
The first connection is done when the first query is run, no need for an async graph creation. BREAKING CHANGE: The Graph::new and Graph::connect methods are no longer `async`, any `.await` after calling them must be removed.
1 parent 7561bbe commit 9c67cd4

File tree

6 files changed

+15
-20
lines changed

6 files changed

+15
-20
lines changed

lib/examples/concurrent_writes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ async fn main() {
1818
.build()
1919
.unwrap(),
2020
)
21-
.await
2221
.unwrap();
2322

2423
stream::iter(1..=1337)

lib/src/graph.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Graph {
6666
/// Connects to the database with configurations provided.
6767
///
6868
/// You can build a config using [`ConfigBuilder::default()`].
69-
pub async fn connect(config: Config) -> Result<Self> {
69+
pub fn connect(config: Config) -> Result<Self> {
7070
#[cfg(feature = "unstable-bolt-protocol-impl-v2")]
7171
{
7272
let info = ConnectionInfo::new(
@@ -77,16 +77,16 @@ impl Graph {
7777
)?;
7878
if matches!(info.routing, Routing::Yes(_)) {
7979
debug!("Routing enabled, creating a routed connection manager");
80-
let pool = Routed(
81-
RoutedConnectionManager::new(&config, Box::new(ClusterRoutingTableProvider))
82-
.await?,
83-
);
80+
let pool = Routed(RoutedConnectionManager::new(
81+
&config,
82+
Box::new(ClusterRoutingTableProvider),
83+
)?);
8484
Ok(Graph {
8585
config: config.into_live_config(),
8686
pool,
8787
})
8888
} else {
89-
let pool = Direct(create_pool(&config).await?);
89+
let pool = Direct(create_pool(&config)?);
9090
Ok(Graph {
9191
config: config.into_live_config(),
9292
pool,
@@ -95,7 +95,7 @@ impl Graph {
9595
}
9696
#[cfg(not(feature = "unstable-bolt-protocol-impl-v2"))]
9797
{
98-
let pool = Direct(create_pool(&config).await?);
98+
let pool = Direct(create_pool(&config)?);
9999
Ok(Graph {
100100
config: config.into_live_config(),
101101
pool,
@@ -104,7 +104,7 @@ impl Graph {
104104
}
105105

106106
/// Connects to the database with default configurations
107-
pub async fn new(
107+
pub fn new(
108108
uri: impl Into<String>,
109109
user: impl Into<String>,
110110
password: impl Into<String>,
@@ -114,7 +114,7 @@ impl Graph {
114114
.user(user)
115115
.password(password)
116116
.build()?;
117-
Self::connect(config).await
117+
Self::connect(config)
118118
}
119119

120120
/// Starts a new transaction on the configured database.

lib/src/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Manager for ConnectionManager {
5555
}
5656
}
5757

58-
pub async fn create_pool(config: &Config) -> Result<ConnectionPool> {
58+
pub fn create_pool(config: &Config) -> Result<ConnectionPool> {
5959
let mgr = ConnectionManager::new(
6060
&config.uri,
6161
&config.user,

lib/src/routing/connection_registry.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ async fn refresh_routing_table(
9090
create_pool(&Config {
9191
uri,
9292
..config.clone()
93-
})
94-
.await?,
93+
})?,
9594
);
9695
}
9796
registry.connections.retain(|k, _| servers.contains(k));
@@ -103,7 +102,7 @@ async fn refresh_routing_table(
103102
Ok(routing_table.ttl)
104103
}
105104

106-
pub(crate) async fn start_background_updater(
105+
pub(crate) fn start_background_updater(
107106
config: &Config,
108107
registry: Arc<ConnectionRegistry>,
109108
provider: Arc<Box<dyn RoutingTableProvider>>,

lib/src/routing/routed_connection_manager.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ pub struct RoutedConnectionManager {
2525
}
2626

2727
impl RoutedConnectionManager {
28-
pub async fn new(
29-
config: &Config,
30-
provider: Box<dyn RoutingTableProvider>,
31-
) -> Result<Self, Error> {
28+
pub fn new(config: &Config, provider: Box<dyn RoutingTableProvider>) -> Result<Self, Error> {
3229
let backoff = Arc::new(
3330
ExponentialBackoffBuilder::new()
3431
.with_initial_interval(Duration::from_millis(1))
@@ -40,7 +37,7 @@ impl RoutedConnectionManager {
4037

4138
let connection_registry = Arc::new(ConnectionRegistry::default());
4239
let channel =
43-
start_background_updater(config, connection_registry.clone(), provider.into()).await;
40+
start_background_updater(config, connection_registry.clone(), provider.into());
4441
Ok(RoutedConnectionManager {
4542
load_balancing_strategy: Arc::new(RoundRobinStrategy::default()),
4643
bookmarks: Arc::new(Mutex::new(vec![])),

lib/tests/container.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl Neo4jContainer {
245245
.build()
246246
.unwrap();
247247

248-
Graph::connect(config).await.unwrap()
248+
Graph::connect(config).unwrap()
249249
}
250250
}
251251

0 commit comments

Comments
 (0)