Change pin_mut! to select!

This commit is contained in:
Daniel Karzel 2020-12-18 11:37:02 +11:00
parent 093cbaa4b4
commit e6493784bf

View File

@ -7,13 +7,10 @@ use crate::{
}; };
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use async_recursion::async_recursion; use async_recursion::async_recursion;
use futures::{
future::{select, Either},
pin_mut,
};
use libp2p::{core::Multiaddr, PeerId}; use libp2p::{core::Multiaddr, PeerId};
use rand::{CryptoRng, RngCore}; use rand::{CryptoRng, RngCore};
use std::{convert::TryFrom, fmt, sync::Arc}; use std::{convert::TryFrom, fmt, sync::Arc};
use tokio::select;
use tracing::info; use tracing::info;
use uuid::Uuid; use uuid::Uuid;
use xmr_btc::{ use xmr_btc::{
@ -287,12 +284,13 @@ where
let bitcoin_wallet = bitcoin_wallet.clone(); let bitcoin_wallet = bitcoin_wallet.clone();
let t1_timeout = state4_clone.wait_for_t1(bitcoin_wallet.as_ref()); let t1_timeout = state4_clone.wait_for_t1(bitcoin_wallet.as_ref());
pin_mut!(enc_sig_sent_watcher); select! {
pin_mut!(t1_timeout); _ = enc_sig_sent_watcher => {
BobState::EncSigSent(state, alice_peer_id)
match select(enc_sig_sent_watcher, t1_timeout).await { },
Either::Left((..)) => BobState::EncSigSent(state, alice_peer_id), _ = t1_timeout => {
Either::Right((..)) => BobState::T1Expired(state), BobState::T1Expired(state)
}
} }
} else { } else {
BobState::T1Expired(state) BobState::T1Expired(state)
@ -318,12 +316,13 @@ where
let redeem_watcher = state_clone.watch_for_redeem_btc(bitcoin_wallet.as_ref()); let redeem_watcher = state_clone.watch_for_redeem_btc(bitcoin_wallet.as_ref());
let t1_timeout = state_clone.wait_for_t1(bitcoin_wallet.as_ref()); let t1_timeout = state_clone.wait_for_t1(bitcoin_wallet.as_ref());
pin_mut!(redeem_watcher); select! {
pin_mut!(t1_timeout); state5 = redeem_watcher => {
BobState::BtcRedeemed(state5?)
match select(redeem_watcher, t1_timeout).await { },
Either::Left((val, _)) => BobState::BtcRedeemed(val?), _ = t1_timeout => {
Either::Right((..)) => BobState::T1Expired(state), BobState::T1Expired(state)
}
} }
} else { } else {
BobState::T1Expired(state) BobState::T1Expired(state)