This commit is contained in:
azw 2024-05-09 09:31:08 +08:00
parent cba1ec0d84
commit d7b39fee44
2 changed files with 12 additions and 5 deletions

View File

@ -54,8 +54,11 @@ impl f9::app::UserApp for UserApp {
fn update(&mut self) { fn update(&mut self) {
self.net_msg_queue.borrow_mut().fetch(); self.net_msg_queue.borrow_mut().fetch();
if self.net_msg_queue.borrow_mut().empty() { let work_list = self.net_msg_queue.borrow_mut().work_list.clone();
while !work_list.borrow().empty() {
println!("work_list exec");
let node = &work_list.borrow().first_entry();
node.upgrade().unwrap().borrow_mut().entry.borrow_mut().del_init();
} }
} }

View File

@ -21,7 +21,7 @@ use actix::prelude::*;
use bytes::{BufMut, BytesMut}; use bytes::{BufMut, BytesMut};
use actix_web::web::Bytes; use actix_web::web::Bytes;
use crate::app::UserApp; use crate::app::UserApp;
use crate::{GSResponse, MAX_PACKET_LEN}; use crate::{AppStateWithCounter, GSResponse, MAX_PACKET_LEN};
#[derive(SharedFromSelf)] #[derive(SharedFromSelf)]
#[derive(Singleton)] #[derive(Singleton)]
@ -184,21 +184,25 @@ impl WsListener {
//self.work_thread = Arc::new(Some(1)); //self.work_thread = Arc::new(Some(1));
{ {
self.work_thread = Some(thread::spawn(|| { self.work_thread = Some(thread::spawn(|| {
println!("hello2");
let mut rt = tokio::runtime::Builder::new_multi_thread() let mut rt = tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()
.build() .build()
.unwrap(); .unwrap();
rt.block_on(async { rt.block_on(async {
let counter = web::Data::new(AppStateWithCounter {
counter: Mutex::new(0),
});
HttpServer::new(move || { HttpServer::new(move || {
// move counter into the closure // move counter into the closure
ActixApp::new() // <- register the created data ActixApp::new() // <- register the created data
.route("/", web::get().to(crate::index)) .app_data(counter.clone())
.route("/", web::get().to(index))
}) })
.bind(("0.0.0.0", 8080))? .bind(("0.0.0.0", 8080))?
.run() .run()
.await .await
}); });
println!("hello2");
})); }));
println!("hello3"); println!("hello3");
} }