Skip to content

Commit 2e54c5d

Browse files
committed
impl Drop for EventLoop
1 parent 4918ed8 commit 2e54c5d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

core/src/net/event_loop.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ pub(crate) struct EventLoop<'e> {
5858
phantom_data: PhantomData<&'e EventLoop<'e>>,
5959
}
6060

61+
impl Drop for EventLoop<'_> {
62+
fn drop(&mut self) {
63+
if std::thread::panicking() {
64+
return;
65+
}
66+
self.stop_sync(Duration::from_secs(30))
67+
.unwrap_or_else(|e| panic!("Failed to stop event-loop {} due to {e} !", self.name()));
68+
assert_eq!(
69+
PoolState::Stopped,
70+
self.state(),
71+
"The event-loop is not stopped !"
72+
);
73+
}
74+
}
75+
6176
impl<'e> Deref for EventLoop<'e> {
6277
type Target = CoroutinePool<'e>;
6378

0 commit comments

Comments
 (0)