Add MutexExt trait

This commit is contained in:
Sosthene00 2024-03-21 18:06:17 +01:00
parent a28f40fa0c
commit d33c3e9735

View File

@ -58,6 +58,17 @@ type PeerMap = Arc<Mutex<HashMap<SocketAddr, Tx>>>;
const FAUCET_AMT: Amount = Amount::from_sat(1000);
pub(crate) trait MutexExt<T> {
fn lock_anyhow(&self) -> Result<MutexGuard<T>, Error>;
}
impl<T: Debug> MutexExt<T> for Mutex<T> {
fn lock_anyhow(&self) -> Result<MutexGuard<T>, Error> {
self.lock()
.map_err(|e| Error::msg(format!("Failed to lock: {}", e)))
}
}
enum BroadcastType {
Sender(SocketAddr),
ExcludeSender(SocketAddr),