refactor(eventloop): rename the thread
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use super::client::Client;
|
||||
use anyhow::{anyhow, Result};
|
||||
use libstardustxr::server;
|
||||
use mio::net::UnixListener;
|
||||
use mio::unix::pipe;
|
||||
@@ -8,8 +9,6 @@ use slab::Slab;
|
||||
use std::io::Write;
|
||||
use std::thread::{self, JoinHandle};
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
pub struct EventLoop {
|
||||
pub socket_path: String,
|
||||
join_handle: Option<JoinHandle<Result<()>>>,
|
||||
@@ -22,7 +21,9 @@ impl EventLoop {
|
||||
.ok_or_else(|| std::io::Error::from(std::io::ErrorKind::Other))?;
|
||||
let mut socket = UnixListener::bind(socket_path.clone())?;
|
||||
let (sender, mut receiver) = pipe::new()?;
|
||||
let join_handle = Some(thread::spawn(move || -> Result<()> {
|
||||
let join_handle = thread::Builder::new()
|
||||
.name("event_loop".to_owned())
|
||||
.spawn(move || -> Result<()> {
|
||||
let mut clients: Slab<Option<RcCell<Client>>> = Slab::new();
|
||||
let mut poll = Poll::new()?;
|
||||
let mut events = Events::with_capacity(1024);
|
||||
@@ -78,7 +79,8 @@ impl EventLoop {
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
})
|
||||
.ok();
|
||||
Ok(EventLoop {
|
||||
socket_path,
|
||||
join_handle,
|
||||
@@ -94,8 +96,7 @@ impl Drop for EventLoop {
|
||||
let _ = self
|
||||
.join_handle
|
||||
.take()
|
||||
.unwrap()
|
||||
.join()
|
||||
.map(|handle| handle.join())
|
||||
.expect("Couldn't join the event loop thread at drop");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user