Skip to content

Commit

Permalink
#372 with comments fixed (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu-Lala authored Jun 26, 2024
1 parent 74814de commit e39ff5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ build = "build.rs"
rust-version = "1.74.0"

[features]
default = ["rustls"]
default = ["rustls", "default-runtime"]
default-runtime = ["async-global-executor-trait", "async-reactor-trait"]
codegen = ["codegen-internal", "amq-protocol/codegen"]
codegen-internal = ["amq-protocol-codegen", "serde_json"]
native-tls = ["amq-protocol/native-tls"]
Expand Down Expand Up @@ -44,6 +45,11 @@ default-features = false
[dependencies.async-global-executor-trait]
version = "^2.1"
features = ["async-io"]
optional = true

[dependencies.async-reactor-trait]
version = "^1.1"
optional = true

[dependencies.flume]
version = "^0.11"
Expand Down
24 changes: 16 additions & 8 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,14 @@ impl Connection {
connect: Box<dyn FnOnce(&AMQPUri) -> HandshakeResult + Send + Sync>,
mut options: ConnectionProperties,
) -> Result<Connection> {
let executor = options
.executor
.take()
.unwrap_or_else(|| Arc::new(async_global_executor_trait::AsyncGlobalExecutor));
let executor = options.executor.take();

#[cfg(feature = "default-runtime")]
let executor =
executor.or_else(|| Some(Arc::new(async_global_executor_trait::AsyncGlobalExecutor)));

let executor = executor
.expect("executor should be provided with no default executor feature was enabled");

let (connect_promise, resolver) = Promise::new();
let connect_uri = uri.clone();
Expand Down Expand Up @@ -337,10 +341,14 @@ impl Connection {
})
});

let reactor = options
.reactor
.take()
.unwrap_or_else(|| Arc::new(async_reactor_trait::AsyncIo));
let reactor = options.reactor.take();

#[cfg(feature = "default-runtime")]
let reactor = reactor.or_else(|| Some(Arc::new(async_reactor_trait::AsyncIo)));

let reactor = reactor
.expect("reactor should be provided with no default reactor feature was enabled");

let socket_state = SocketState::default();
let waker = socket_state.handle();
let internal_rpc = InternalRPC::new(executor.clone(), waker.clone());
Expand Down

0 comments on commit e39ff5d

Please sign in to comment.