feat: rustler: make on_add and on_delete async

This commit is contained in:
Lucas Colombo 2024-05-23 20:36:02 -03:00
parent 729bf7f421
commit 241b7a3814
Signed by: lucas
GPG Key ID: EF34786CFEFFAE35
2 changed files with 6 additions and 6 deletions

View File

@ -99,12 +99,12 @@ impl Rustler for FooRustler {
Ok(()) Ok(())
} }
fn on_add(&mut self, tickers: &[Ticker]) -> Result<()> { async fn on_add(&mut self, tickers: &[Ticker]) -> Result<()> {
info!("(mock) Adding tickers: {:?}", tickers); info!("(mock) Adding tickers: {:?}", tickers);
Ok(()) Ok(())
} }
fn on_delete(&mut self, tickers: &[Ticker]) -> Result<()> { async fn on_delete(&mut self, tickers: &[Ticker]) -> Result<()> {
info!("(mock) Deleting tickers: {:?}", tickers); info!("(mock) Deleting tickers: {:?}", tickers);
Ok(()) Ok(())
} }

View File

@ -253,9 +253,9 @@ pub trait RustlerAccessor {
pub trait Rustler: RustlerAccessor + Send + Sync { pub trait Rustler: RustlerAccessor + Send + Sync {
// #region Unimplemented trait functions // #region Unimplemented trait functions
/// 🐎 » fn called after tickers are added to the rustler /// 🐎 » fn called after tickers are added to the rustler
fn on_add(&mut self, tickers: &[Ticker]) -> Result<()>; async fn on_add(&mut self, tickers: &[Ticker]) -> Result<()>;
/// 🐎 » fn called after tickers are deleted from the rustler /// 🐎 » fn called after tickers are deleted from the rustler
fn on_delete(&mut self, tickers: &[Ticker]) -> Result<()>; async fn on_delete(&mut self, tickers: &[Ticker]) -> Result<()>;
/// 🐎 » connects the rustler to the data source /// 🐎 » connects the rustler to the data source
async fn connect(&mut self) -> Result<()>; async fn connect(&mut self) -> Result<()>;
/// 🐎 » disconnects the rustler from the data source /// 🐎 » disconnects the rustler from the data source
@ -323,7 +323,7 @@ pub trait Rustler: RustlerAccessor + Send + Sync {
} }
if !added_tickers.is_empty() { if !added_tickers.is_empty() {
self.on_add(&added_tickers)?; self.on_add(&added_tickers).await?;
} }
Ok(()) Ok(())
@ -348,7 +348,7 @@ pub trait Rustler: RustlerAccessor + Send + Sync {
} }
if !removed_tickers.is_empty() { if !removed_tickers.is_empty() {
self.on_delete(&removed_tickers)?; self.on_delete(&removed_tickers).await?;
} }
Ok(()) Ok(())