-
-
Couldn't load subscription status.
- Fork 4.2k
Replace async_channel with event_listener in bevy_tasks #11942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
63e8c8f
2461527
76e29f6
ed1da16
df72279
0d6a458
93fa142
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ use std::{ | |
|
|
||
| use async_task::FallibleTask; | ||
| use concurrent_queue::ConcurrentQueue; | ||
| use event_listener::Event; | ||
| use futures_lite::FutureExt; | ||
|
|
||
| use crate::{ | ||
|
|
@@ -115,7 +116,7 @@ pub struct TaskPool { | |
|
|
||
| /// Inner state of the pool | ||
| threads: Vec<JoinHandle<()>>, | ||
| shutdown_tx: async_channel::Sender<()>, | ||
| shutdown: Arc<event_listener::Event>, | ||
| } | ||
|
|
||
| impl TaskPool { | ||
|
|
@@ -135,8 +136,7 @@ impl TaskPool { | |
| } | ||
|
|
||
| fn new_internal(builder: TaskPoolBuilder) -> Self { | ||
| let (shutdown_tx, shutdown_rx) = async_channel::unbounded::<()>(); | ||
|
|
||
| let shutdown = Arc::new(Event::new()); | ||
| let executor = Arc::new(async_executor::Executor::new()); | ||
|
|
||
| let num_threads = builder | ||
|
|
@@ -146,7 +146,7 @@ impl TaskPool { | |
| let threads = (0..num_threads) | ||
| .map(|i| { | ||
| let ex = Arc::clone(&executor); | ||
| let shutdown_rx = shutdown_rx.clone(); | ||
| let shutdown = shutdown.clone(); | ||
|
|
||
| let thread_name = if let Some(thread_name) = builder.thread_name.as_deref() { | ||
| format!("{thread_name} ({i})") | ||
|
|
@@ -177,11 +177,9 @@ impl TaskPool { | |
| local_executor.tick().await; | ||
| } | ||
| }; | ||
| block_on(ex.run(tick_forever.or(shutdown_rx.recv()))) | ||
| block_on(ex.run(tick_forever.or(shutdown.listen()))); | ||
| }); | ||
| if let Ok(value) = res { | ||
| // Use unwrap_err because we expect a Closed error | ||
| value.unwrap_err(); | ||
| if res.is_ok() { | ||
| break; | ||
| } | ||
| } | ||
|
|
@@ -194,7 +192,7 @@ impl TaskPool { | |
| Self { | ||
| executor, | ||
| threads, | ||
| shutdown_tx, | ||
| shutdown, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -584,7 +582,7 @@ impl Default for TaskPool { | |
|
|
||
| impl Drop for TaskPool { | ||
| fn drop(&mut self) { | ||
| self.shutdown_tx.close(); | ||
| self.shutdown.notify(self.threads.len()); | ||
|
||
|
|
||
| let panicking = thread::panicking(); | ||
| for join_handle in self.threads.drain(..) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for fully qualified path