-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Replace async_channel with event_listener in bevy_tasks #11942
Closed
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
63e8c8f
Replace async_channel with event_listener
james7132 2461527
Small cleanup
james7132 76e29f6
usize::MAX might be a bit too much.
james7132 ed1da16
Merge branch 'main' into event-listener-shutdown
alice-i-cecile df72279
Try event-listener-strategy
james7132 0d6a458
Merge branch 'main' into event-listener-shutdown
james7132 93fa142
Merge branch 'main' into event-listener-shutdown
james7132 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be worth trying usize::MAX here and seeing if it helps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already tried this above and it doesn't seem to work. |
||
|
||
let panicking = thread::panicking(); | ||
for join_handle in self.threads.drain(..) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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