Skip to content

Commit

Permalink
Merge pull request #14 from oscrim/move-systems-to-preupdate
Browse files Browse the repository at this point in the history
Move systems to preupdate
  • Loading branch information
TotalKrill authored Oct 31, 2024
2 parents 6c7a0ec + 9135fb1 commit f3ea161
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ pub use reqwest::{StatusCode, Version};
#[cfg(not(target_family = "wasm"))]
use {bevy::tasks::Task, futures_lite::future};

/// The [`SystemSet`] that Reqwest systems are added to.
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub struct ReqwestSet;

/// Plugin that allows to send http request using the [reqwest](https://crates.io/crates/reqwest) library from
/// inside bevy.
/// The plugin uses [bevy_eventlister](https://crates.io/crates/bevy_eventlistener) to provide callback style events
/// when the http requests finishes.
/// supports both wasm and native
///
/// The plugin uses [`Observer`] systems to provide callbacks when the http requests finishes.
///
/// Supports both wasm and native.
pub struct ReqwestPlugin {
/// this enables the plugin to insert a new [`Name`] component onto the entity used to drive
/// the http request to completion, if no Name component already exists
Expand All @@ -36,9 +41,7 @@ impl Default for ReqwestPlugin {
}
impl Plugin for ReqwestPlugin {
fn build(&self, app: &mut App) {
if !app.world().contains_resource::<ReqwestClient>() {
app.init_resource::<ReqwestClient>();
}
app.init_resource::<ReqwestClient>();

if self.automatically_name_requests {
// register a hook on the component to add a name to the entity if it doesnt have one already
Expand All @@ -56,15 +59,16 @@ impl Plugin for ReqwestPlugin {
}
//
app.add_systems(
Update,
PreUpdate,
(
// These systems are chained as the callbacks are triggered in PreUpdate
// So if remove_finished_requests runs after poll_inflight_requests_to_bytes
// the entity will be removed before the callback is triggered.
Self::remove_finished_requests,
Self::poll_inflight_requests_to_bytes,
)
.chain(),
.chain()
.in_set(ReqwestSet),
);
}
}
Expand Down Expand Up @@ -116,7 +120,7 @@ impl ReqwestPlugin {
pub struct BevyReqwestBuilder<'a>(EntityCommands<'a>);

impl<'a> BevyReqwestBuilder<'a> {
/// Provide a system where the first argument is [`Trigger<ReqwestResponseEvent>`] that will run on the
/// Provide a system where the first argument is [`Trigger`] [`ReqwestResponseEvent`] that will run on the
/// response from the http request
///
/// # Examples
Expand All @@ -136,7 +140,7 @@ impl<'a> BevyReqwestBuilder<'a> {
self
}

/// Provide a system where the first argument is [`Trigger<ReqwestErrorEvent>`] that will run on the
/// Provide a system where the first argument is [`Trigger`] [`ReqwestErrorEvent`] that will run on the
/// response from the http request
///
/// # Examples
Expand Down

0 comments on commit f3ea161

Please sign in to comment.