mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Don't unnecessarily create async blocks
If our expression directly evaluates to a future, we don't need to create an async block. This requires us to have `EventLoopRun::run` consume the instance instead of just taking a mutable reference (otherwise we run into lifetime issues). However, that is better anyway because `run` is an endless loop so you never get to use the handle afterwards anyway.
This commit is contained in:
parent
a4c25080b6
commit
54bc91581f
@ -100,7 +100,7 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
let rate_service = kraken::RateService::new().await?;
|
let rate_service = kraken::RateService::new().await?;
|
||||||
|
|
||||||
let (mut event_loop, _) = EventLoop::new(
|
let (event_loop, _) = EventLoop::new(
|
||||||
config.network.listen,
|
config.network.listen,
|
||||||
seed,
|
seed,
|
||||||
execution_params,
|
execution_params,
|
||||||
|
@ -149,7 +149,7 @@ async fn main() -> Result<()> {
|
|||||||
);
|
);
|
||||||
let (swap, event_loop) = bob_factory.with_init_params(send_bitcoin).build().await?;
|
let (swap, event_loop) = bob_factory.with_init_params(send_bitcoin).build().await?;
|
||||||
|
|
||||||
let handle = tokio::spawn(async move { event_loop.run().await });
|
let handle = tokio::spawn(event_loop.run());
|
||||||
let swap = bob::run(swap);
|
let swap = bob::run(swap);
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
event_loop_result = handle => {
|
event_loop_result = handle => {
|
||||||
@ -193,7 +193,7 @@ async fn main() -> Result<()> {
|
|||||||
execution_params,
|
execution_params,
|
||||||
);
|
);
|
||||||
let (swap, event_loop) = bob_factory.build().await?;
|
let (swap, event_loop) = bob_factory.build().await?;
|
||||||
let handle = tokio::spawn(async move { event_loop.run().await });
|
let handle = tokio::spawn(event_loop.run());
|
||||||
let swap = bob::run(swap);
|
let swap = bob::run(swap);
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
event_loop_result = handle => {
|
event_loop_result = handle => {
|
||||||
|
@ -158,7 +158,7 @@ where
|
|||||||
self.peer_id
|
self.peer_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&mut self) {
|
pub async fn run(mut self) {
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
swarm_event = self.swarm.next().fuse() => {
|
swarm_event = self.swarm.next().fuse() => {
|
||||||
|
@ -103,7 +103,7 @@ impl TestContext {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let join_handle = tokio::spawn(async move { event_loop.run().await });
|
let join_handle = tokio::spawn(event_loop.run());
|
||||||
|
|
||||||
(swap, BobEventLoopJoinHandle(join_handle))
|
(swap, BobEventLoopJoinHandle(join_handle))
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ impl TestContext {
|
|||||||
|
|
||||||
let (swap, event_loop) = self.bob_params.builder().build().await.unwrap();
|
let (swap, event_loop) = self.bob_params.builder().build().await.unwrap();
|
||||||
|
|
||||||
let join_handle = tokio::spawn(async move { event_loop.run().await });
|
let join_handle = tokio::spawn(event_loop.run());
|
||||||
|
|
||||||
(swap, BobEventLoopJoinHandle(join_handle))
|
(swap, BobEventLoopJoinHandle(join_handle))
|
||||||
}
|
}
|
||||||
@ -376,7 +376,7 @@ where
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let (mut alice_event_loop, alice_swap_handle) = alice::EventLoop::new(
|
let (alice_event_loop, alice_swap_handle) = alice::EventLoop::new(
|
||||||
alice_listen_address.clone(),
|
alice_listen_address.clone(),
|
||||||
alice_seed,
|
alice_seed,
|
||||||
execution_params,
|
execution_params,
|
||||||
@ -390,9 +390,7 @@ where
|
|||||||
|
|
||||||
let alice_peer_id = alice_event_loop.peer_id();
|
let alice_peer_id = alice_event_loop.peer_id();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(alice_event_loop.run());
|
||||||
alice_event_loop.run().await;
|
|
||||||
});
|
|
||||||
|
|
||||||
let bob_params = BobParams {
|
let bob_params = BobParams {
|
||||||
seed: Seed::random().unwrap(),
|
seed: Seed::random().unwrap(),
|
||||||
|
Loading…
Reference in New Issue
Block a user