Introduce `RateUpdate` type alias to reduce duplication

pull/301/head
Thomas Eizinger 3 years ago
parent fd5b38739a
commit c560b3b21a
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96

@ -8,6 +8,8 @@ use std::convert::TryFrom;
use tokio::sync::watch;
use tokio_tungstenite::tungstenite;
type RateUpdate = Result<Rate, Error>;
pub async fn connect() -> Result<RateUpdateStream> {
let (rate_update, rate_update_receiver) = watch::channel(Err(Error::NotYetRetrieved));
@ -95,17 +97,17 @@ pub async fn connect() -> Result<RateUpdateStream> {
#[derive(Clone, Debug)]
pub struct RateUpdateStream {
inner: watch::Receiver<Result<Rate, Error>>,
inner: watch::Receiver<RateUpdate>,
}
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?;
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()
}
}

Loading…
Cancel
Save