Skip to content

Commit

Permalink
Explain EventWriter limits concurrency (bevyengine#11063)
Browse files Browse the repository at this point in the history
Co-authored-by: François <[email protected]>
Co-authored-by: James Liu <[email protected]>
  • Loading branch information
3 people authored Dec 24, 2023
1 parent dc698f0 commit c6b32a2
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit c6b32a2

Please sign in to comment.