| 
									
										
										
										
											2023-10-30 12:35:06 +08:00
										 |  |  | use lib_dispatch::prelude::*;
 | 
					
						
							|  |  |  | use lib_dispatch::runtime::AFPluginRuntime;
 | 
					
						
							| 
									
										
										
										
											2024-08-19 22:08:10 +08:00
										 |  |  | use std::sync::Arc;
 | 
					
						
							|  |  |  | use tokio::task::LocalSet;
 | 
					
						
							| 
									
										
										
										
											2023-10-30 12:35:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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";
 | 
					
						
							| 
									
										
										
										
											2024-08-19 22:08:10 +08:00
										 |  |  |   let runtime = Arc::new(AFPluginRuntime::new().unwrap());
 | 
					
						
							| 
									
										
										
										
											2024-08-20 17:07:54 +08:00
										 |  |  |   #[allow(clippy::arc_with_non_send_sync)]
 | 
					
						
							| 
									
										
										
										
											2024-08-19 22:08:10 +08:00
										 |  |  |   let dispatch = Arc::new(AFPluginDispatcher::new(
 | 
					
						
							| 
									
										
										
										
											2024-01-06 00:37:26 +08:00
										 |  |  |     runtime,
 | 
					
						
							|  |  |  |     vec![AFPlugin::new().event(event, hello)],
 | 
					
						
							|  |  |  |   ));
 | 
					
						
							| 
									
										
										
										
											2023-02-13 09:29:49 +08:00
										 |  |  |   let request = AFPluginRequest::new(event);
 | 
					
						
							| 
									
										
										
										
											2024-08-20 14:16:24 +08:00
										 |  |  |   let local_set = LocalSet::new();
 | 
					
						
							|  |  |  |   local_set
 | 
					
						
							|  |  |  |     .run_until(AFPluginDispatcher::async_send_with_callback(
 | 
					
						
							|  |  |  |       dispatch.as_ref(),
 | 
					
						
							|  |  |  |       request,
 | 
					
						
							|  |  |  |       |resp| {
 | 
					
						
							|  |  |  |         Box::pin(async move {
 | 
					
						
							|  |  |  |           dbg!(&resp);
 | 
					
						
							|  |  |  |         })
 | 
					
						
							|  |  |  |       },
 | 
					
						
							|  |  |  |     ))
 | 
					
						
							|  |  |  |     .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
										 |  |  | }
 |