Add async_unit_result_context, rename read_collection_file
This commit is contained in:
		
					parent
					
						
							
								5055583487
							
						
					
				
			
			
				commit
				
					
						1e9ff1057a
					
				
			
		
					 3 changed files with 25 additions and 12 deletions
				
			
		
							
								
								
									
										10
									
								
								src/error.rs
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/error.rs
									
										
									
									
									
								
							|  | @ -29,3 +29,13 @@ pub async fn async_result_context < | ||||||
| 		Err (error) => on_failure (error) , | 		Err (error) => on_failure (error) , | ||||||
| 	} ; | 	} ; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | pub async fn async_unit_result_context < | ||||||
|  | 	AsyncFunction : Future < Output = Result <()> > , | ||||||
|  | 	FailureHandler : Fn (ZoodexError) , | ||||||
|  | > ( | ||||||
|  | 	function : AsyncFunction , | ||||||
|  | 	on_failure : FailureHandler , | ||||||
|  | ) { | ||||||
|  | 	async_result_context ( function , |_| () , on_failure ) . await ; | ||||||
|  | } | ||||||
|  |  | ||||||
							
								
								
									
										25
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										25
									
								
								src/main.rs
									
										
									
									
									
								
							|  | @ -26,17 +26,20 @@ fn on_activate ( app : & Application ) { | ||||||
| 	ui . show_window () ; | 	ui . show_window () ; | ||||||
| 
 | 
 | ||||||
| 	spawn_future_local ( async move { | 	spawn_future_local ( async move { | ||||||
| 		async_result_context ( async { | 		async_unit_result_context ( | ||||||
| 			let collection = spawn_blocking ( || read_collection_file () ) | 			async { | ||||||
| 				. await ? ? ; | 				let collection = spawn_blocking ( || | ||||||
| 			ui . render_collection (collection) ; | 					get_collection_from_file () ) . await ? ? ; | ||||||
|  | 				ui . render_collection (collection) ; | ||||||
| 
 | 
 | ||||||
| 			Ok (()) | 				Ok (()) | ||||||
| 		} , |_| () , |error| { | 			} , | ||||||
| 			match error { | 			|error| { | ||||||
| 				CollectionFileError => eprintln ! ("Could not open collection file") , | 				match error { | ||||||
| 			} ; | 					CollectionFileError => eprintln ! ("Could not open collection file") , | ||||||
| 			ui . close_window () ; | 				} ; | ||||||
| 		} ) . await ; | 				ui . close_window () ; | ||||||
|  | 			} , | ||||||
|  | 		) . await ; | ||||||
| 	} ) ; | 	} ) ; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ use crate :: { collection :: * , error :: { * , ZoodexError :: * } } ; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| pub fn read_collection_file () -> Result <Collection> { | pub fn get_collection_from_file () -> Result <Collection> { | ||||||
| 	let sqlite_connection = Connection :: open ("zoodex.sqlite") ? ; | 	let sqlite_connection = Connection :: open ("zoodex.sqlite") ? ; | ||||||
| 
 | 
 | ||||||
| 	let mut films_query = sqlite_connection | 	let mut films_query = sqlite_connection | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue