Skip to content
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

Explain EventWriter limits concurrency #11063

Merged
merged 3 commits into from
Dec 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/bevy_ecs/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ impl<E: Event> DerefMut for EventSequence<E> {
}

/// Reads events of type `T` in order and tracks which events have already been read.
///
/// # Concurrency
///
/// Unlike [`EventWriter<T>`], systems with `EventReader<T>` param can be executed concurrently
/// (but not concurrently with `EventWriter<T>` systems for the same event type).
#[derive(SystemParam, Debug)]
pub struct EventReader<'w, 's, E: Event> {
reader: Local<'s, ManualEventReader<E>>,
Expand Down Expand Up @@ -484,7 +489,12 @@ impl<'w, 's, E: Event> EventReader<'w, 's, E> {
/// # bevy_ecs::system::assert_is_system(my_system);
/// ```
///
/// # Limitations
/// # Concurrency
///
/// `EventWriter` param has [`ResMut<Events<T>>`](Events) inside. So two systems declaring `EventWriter<T>` params
/// for the same event type won't be executed concurrently.
///
/// # Untyped events
///
/// `EventWriter` can only send events of one specific type, which must be known at compile-time.
/// This is not a problem most of the time, but you may find a situation where you cannot know
Expand Down