Perform db action inline
This commit is contained in:
		
							parent
							
								
									cdef00f844
								
							
						
					
					
						commit
						4c373e562b
					
				
					 3 changed files with 17 additions and 16 deletions
				
			
		|  | @ -45,34 +45,32 @@ impl Db { | ||||||
|         Ok(self.actor.send(DbQuery(f)).await?.await?) |         Ok(self.actor.send(DbQuery(f)).await?.await?) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn remove_listener(&self, inbox: XsdAnyUri) { |     pub async fn remove_listener(&self, inbox: XsdAnyUri) -> Result<(), MyError> { | ||||||
|         self.actor.do_send(DbQuery(move |pool: Pool| { |         self.execute_inline(move |pool: Pool| { | ||||||
|             let inbox = inbox.clone(); |             let inbox = inbox.clone(); | ||||||
| 
 | 
 | ||||||
|             async move { |             async move { | ||||||
|                 let conn = pool.get().await?; |                 let conn = pool.get().await?; | ||||||
| 
 | 
 | ||||||
|                 remove_listener(&conn, &inbox).await.map_err(|e| { |                 remove_listener(&conn, &inbox).await | ||||||
|                     error!("Error removing listener, {}", e); |  | ||||||
|                     e |  | ||||||
|                 }) |  | ||||||
|             } |             } | ||||||
|         })); |         }) | ||||||
|  |         .await? | ||||||
|  |         .map_err(MyError::from) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn add_listener(&self, inbox: XsdAnyUri) { |     pub async fn add_listener(&self, inbox: XsdAnyUri) -> Result<(), MyError> { | ||||||
|         self.actor.do_send(DbQuery(move |pool: Pool| { |         self.execute_inline(move |pool: Pool| { | ||||||
|             let inbox = inbox.clone(); |             let inbox = inbox.clone(); | ||||||
| 
 | 
 | ||||||
|             async move { |             async move { | ||||||
|                 let conn = pool.get().await?; |                 let conn = pool.get().await?; | ||||||
| 
 | 
 | ||||||
|                 add_listener(&conn, &inbox).await.map_err(|e| { |                 add_listener(&conn, &inbox).await | ||||||
|                     error!("Error adding listener, {}", e); |  | ||||||
|                     e |  | ||||||
|                 }) |  | ||||||
|             } |             } | ||||||
|         })); |         }) | ||||||
|  |         .await? | ||||||
|  |         .map_err(MyError::from) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -8,6 +8,9 @@ use tokio::sync::oneshot::error::RecvError; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, thiserror::Error)] | #[derive(Debug, thiserror::Error)] | ||||||
| pub enum MyError { | pub enum MyError { | ||||||
|  |     #[error("Error in db, {0}")] | ||||||
|  |     DbError(#[from] anyhow::Error), | ||||||
|  | 
 | ||||||
|     #[error("Couldn't parse key, {0}")] |     #[error("Couldn't parse key, {0}")] | ||||||
|     Key(#[from] KeyError), |     Key(#[from] KeyError), | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -100,7 +100,7 @@ async fn handle_undo( | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let inbox = actor.inbox().to_owned(); |     let inbox = actor.inbox().to_owned(); | ||||||
|     db.remove_listener(inbox); |     db.remove_listener(inbox).await?; | ||||||
| 
 | 
 | ||||||
|     let undo = generate_undo_follow(state, &actor.id, &my_id)?; |     let undo = generate_undo_follow(state, &actor.id, &my_id)?; | ||||||
| 
 | 
 | ||||||
|  | @ -169,7 +169,7 @@ async fn handle_follow( | ||||||
|         let follow = generate_follow(state, &actor.id, &my_id)?; |         let follow = generate_follow(state, &actor.id, &my_id)?; | ||||||
| 
 | 
 | ||||||
|         let inbox = actor.inbox().to_owned(); |         let inbox = actor.inbox().to_owned(); | ||||||
|         db.add_listener(inbox); |         db.add_listener(inbox).await?; | ||||||
| 
 | 
 | ||||||
|         let client2 = client.clone(); |         let client2 = client.clone(); | ||||||
|         let inbox = actor.inbox().clone(); |         let inbox = actor.inbox().clone(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue