| 
									
										
										
										
											2021-09-04 15:12:53 +08:00
										 |  |  | use std::sync::Arc;
 | 
					
						
							| 
									
										
										
										
											2021-06-29 16:52:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-30 12:35:06 +08:00
										 |  |  | use lib_dispatch::prelude::*;
 | 
					
						
							|  |  |  | use lib_dispatch::runtime::AFPluginRuntime;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-23 12:14:00 +08:00
										 |  |  | pub async fn hello() -> String {
 | 
					
						
							| 
									
										
										
										
											2023-02-13 09:29:49 +08:00
										 |  |  |   "say hello".to_string()
 | 
					
						
							| 
									
										
										
										
											2022-01-23 12:14:00 +08:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2021-06-29 16:52:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-02 20:45:51 +08:00
										 |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2021-09-04 15:12:53 +08:00
										 |  |  | async fn test() {
 | 
					
						
							| 
									
										
										
										
											2023-02-13 09:29:49 +08:00
										 |  |  |   let event = "1";
 | 
					
						
							| 
									
										
										
										
											2023-10-30 12:35:06 +08:00
										 |  |  |   let runtime = Arc::new(AFPluginRuntime::new().unwrap());
 | 
					
						
							| 
									
										
										
										
											2024-01-06 00:37:26 +08:00
										 |  |  |   let dispatch = Arc::new(AFPluginDispatcher::new(
 | 
					
						
							|  |  |  |     runtime,
 | 
					
						
							|  |  |  |     vec![AFPlugin::new().event(event, hello)],
 | 
					
						
							|  |  |  |   ));
 | 
					
						
							| 
									
										
										
										
											2023-02-13 09:29:49 +08:00
										 |  |  |   let request = AFPluginRequest::new(event);
 | 
					
						
							| 
									
										
										
										
											2024-01-30 05:36:27 +08:00
										 |  |  |   let _ = AFPluginDispatcher::async_send_with_callback(dispatch.as_ref(), request, |resp| {
 | 
					
						
							| 
									
										
										
										
											2023-02-13 09:29:49 +08:00
										 |  |  |     Box::pin(async move {
 | 
					
						
							|  |  |  |       dbg!(&resp);
 | 
					
						
							| 
									
										
										
										
											2021-07-08 13:47:11 +08:00
										 |  |  |     })
 | 
					
						
							| 
									
										
										
										
											2023-02-13 09:29:49 +08:00
										 |  |  |   })
 | 
					
						
							|  |  |  |   .await;
 | 
					
						
							| 
									
										
										
										
											2021-09-04 15:12:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 09:29:49 +08:00
										 |  |  |   std::mem::forget(dispatch);
 | 
					
						
							| 
									
										
										
										
											2021-06-29 16:52:29 +08:00
										 |  |  | }
 |