mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Introduce RateUpdate
type alias to reduce duplication
This commit is contained in:
parent
fd5b38739a
commit
c560b3b21a
@ -8,6 +8,8 @@ use std::convert::TryFrom;
|
|||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
use tokio_tungstenite::tungstenite;
|
use tokio_tungstenite::tungstenite;
|
||||||
|
|
||||||
|
type RateUpdate = Result<Rate, Error>;
|
||||||
|
|
||||||
pub async fn connect() -> Result<RateUpdateStream> {
|
pub async fn connect() -> Result<RateUpdateStream> {
|
||||||
let (rate_update, rate_update_receiver) = watch::channel(Err(Error::NotYetRetrieved));
|
let (rate_update, rate_update_receiver) = watch::channel(Err(Error::NotYetRetrieved));
|
||||||
|
|
||||||
@ -95,17 +97,17 @@ pub async fn connect() -> Result<RateUpdateStream> {
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RateUpdateStream {
|
pub struct RateUpdateStream {
|
||||||
inner: watch::Receiver<Result<Rate, Error>>,
|
inner: watch::Receiver<RateUpdate>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RateUpdateStream {
|
impl RateUpdateStream {
|
||||||
pub async fn wait_for_update(&mut self) -> Result<Result<Rate, Error>> {
|
pub async fn wait_for_update(&mut self) -> Result<RateUpdate> {
|
||||||
self.inner.changed().await?;
|
self.inner.changed().await?;
|
||||||
|
|
||||||
Ok(self.inner.borrow().clone())
|
Ok(self.inner.borrow().clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn latest_update(&mut self) -> Result<Rate, Error> {
|
pub fn latest_update(&mut self) -> RateUpdate {
|
||||||
self.inner.borrow().clone()
|
self.inner.borrow().clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user