Explain EventWriter limits concurrency (#11063)

Co-authored-by: François <mockersf@gmail.com>
Co-authored-by: James Liu <contact@jamessliu.com>
This commit is contained in:
Stepan Koltsov 2023-12-24 17:45:21 +00:00 committed by GitHub
parent dc698f0174
commit c6b32a2140
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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>>,
@ -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