♻️ Remove some unused code
							parent
							
								
									05a83854f9
								
							
						
					
					
						commit
						a94741261f
					
				|  | @ -27,11 +27,5 @@ async fn main () -> Result <(), Box <dyn Error>> { | |||
| 		toml::from_str (&config_s).expect (&format! ("Can't parse {:?} as TOML", config_file_path)) | ||||
| 	}; | ||||
| 	
 | ||||
| 	let opt = Opt::from_args (); | ||||
| 	
 | ||||
| 	let opt = ptth::server::Opt { | ||||
| 		
 | ||||
| 	}; | ||||
| 	
 | ||||
| 	ptth::server::main (config_file, opt).await | ||||
| 	ptth::server::main (config_file).await | ||||
| } | ||||
|  |  | |||
|  | @ -114,11 +114,7 @@ mod tests { | |||
| 				file_server_root: None, | ||||
| 			}; | ||||
| 			spawn (async move { | ||||
| 				let opt = server::Opt { | ||||
| 					
 | ||||
| 				}; | ||||
| 				
 | ||||
| 				server::main (config_file, opt).await.unwrap (); | ||||
| 				server::main (config_file).await.unwrap (); | ||||
| 			}); | ||||
| 			
 | ||||
| 			tokio::time::delay_for (std::time::Duration::from_millis (500)).await; | ||||
|  |  | |||
|  | @ -1,5 +1,3 @@ | |||
| pub mod watcher; | ||||
| 
 | ||||
| use std::{ | ||||
| 	error::Error, | ||||
| 	collections::*, | ||||
|  |  | |||
|  | @ -1,79 +0,0 @@ | |||
| // Watchers on the wall was the last good episode of Game of Thrones
 | ||||
| 
 | ||||
| use std::{ | ||||
| 	collections::*, | ||||
| 	sync::Arc, | ||||
| 	time::Duration, | ||||
| }; | ||||
| 
 | ||||
| use futures::channel::oneshot; | ||||
| use tokio::{ | ||||
| 	sync::Mutex, | ||||
| 	time::delay_for, | ||||
| }; | ||||
| 
 | ||||
| pub struct Watchers <T> { | ||||
| 	pub senders: HashMap <String, oneshot::Sender <T>>, | ||||
| } | ||||
| 
 | ||||
| impl <T> Default for Watchers <T> { | ||||
| 	fn default () -> Self { | ||||
| 		Self { | ||||
| 			senders: Default::default (), | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| impl <T: 'static + Send + Sync> Watchers <T> { | ||||
| 	pub fn add_watcher_with_id (&mut self, s: oneshot::Sender <T>, id: String) { | ||||
| 		self.senders.insert (id, s); | ||||
| 	} | ||||
| 	
 | ||||
| 	pub fn remove_watcher (&mut self, id: &str) { | ||||
| 		self.senders.remove (id); | ||||
| 	} | ||||
| 	
 | ||||
| 	pub fn wake_one (&mut self, msg: T, id: &str) -> bool { | ||||
| 		//println! ("wake_one {}", id);
 | ||||
| 		
 | ||||
| 		if let Some (waiter) = self.senders.remove (id) { | ||||
| 			waiter.send (msg).ok (); | ||||
| 			true | ||||
| 		} | ||||
| 		else { | ||||
| 			false | ||||
| 		} | ||||
| 	} | ||||
| 	
 | ||||
| 	pub fn num_watchers (&self) -> usize { | ||||
| 		self.senders.len () | ||||
| 	} | ||||
| 	
 | ||||
| 	pub async fn long_poll (that: Arc <Mutex <Self>>, id: String) -> Option <T> { | ||||
| 		//println! ("long_poll {}", id);
 | ||||
| 		
 | ||||
| 		let (s, r) = oneshot::channel (); | ||||
| 		let timeout = Duration::from_secs (5); | ||||
| 		
 | ||||
| 		let id_2 = id.clone (); | ||||
| 		{ | ||||
| 			let mut that = that.lock ().await; | ||||
| 			that.add_watcher_with_id (s, id_2); | ||||
| 			//println! ("Added server {}", id);
 | ||||
| 		} | ||||
| 		
 | ||||
| 		tokio::spawn (async move { | ||||
| 			delay_for (timeout).await; | ||||
| 			let mut that = that.lock ().await; | ||||
| 			that.remove_watcher (&id); | ||||
| 			//println! ("Removed server {}", id);
 | ||||
| 		}); | ||||
| 		
 | ||||
| 		if let Ok (message) = r.await { | ||||
| 			Some (message) | ||||
| 		} | ||||
| 		else { | ||||
| 			None | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | @ -24,7 +24,6 @@ pub mod file_server; | |||
| 
 | ||||
| struct ServerState { | ||||
| 	config: Config, | ||||
| 	opt: Opt, | ||||
| 	handlebars: Handlebars <'static>, | ||||
| 	client: Client, | ||||
| } | ||||
|  | @ -109,12 +108,7 @@ pub struct Config { | |||
| 	pub file_server_root: Option <PathBuf>, | ||||
| } | ||||
| 
 | ||||
| #[derive (Clone)] | ||||
| pub struct Opt { | ||||
| 	
 | ||||
| } | ||||
| 
 | ||||
| pub async fn main (config_file: ConfigFile, opt: Opt) 
 | ||||
| pub async fn main (config_file: ConfigFile) 
 | ||||
| -> Result <(), Box <dyn Error>> 
 | ||||
| { | ||||
| 	use std::convert::TryInto; | ||||
|  | @ -140,7 +134,6 @@ pub async fn main (config_file: ConfigFile, opt: Opt) | |||
| 			relay_url: config_file.relay_url, | ||||
| 			file_server_root: config_file.file_server_root, | ||||
| 		}, | ||||
| 		opt, | ||||
| 		handlebars, | ||||
| 		client, | ||||
| 	}); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 _
						_