Skip to content

Add App::setup_non_send, deprecate insert_non_send#25067

Open
Supremesv715 wants to merge 1 commit into
bevyengine:mainfrom
Supremesv715:non
Open

Add App::setup_non_send, deprecate insert_non_send#25067
Supremesv715 wants to merge 1 commit into
bevyengine:mainfrom
Supremesv715:non

Conversation

@Supremesv715

Copy link
Copy Markdown
Contributor

Objective

  • App::insert_non_send constructs !Send values immediately at the app-building call site, which can put them on the wrong thread relative to the runner (e.g. WinitPlugin).
  • Provide a deferred API so !Send data is created on the thread that actually runs the app.

Solution

  • Add App::setup_non_send, which queues a Send closure and runs it once at the start of App::run on the calling thread.
  • Deprecate App::insert_non_send (and update the insert_non_send_resource note) in favor of setup_non_send.
  • Migrate examples/app/log_layers_ecs.rs and add a migration guide.
  • App::init_non_send is unchanged.

Testing

  • Added unit tests covering deferred execution and FIFO ordering of queued setups.
  • Reviewers can run:
    • cargo test -p bevy_app setup_non_send
    • cargo run --example log_layers_ecs

@alice-i-cecile alice-i-cecile added A-App Bevy apps and plugins D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 20, 2026
@alice-i-cecile
alice-i-cecile requested a review from NthTensor July 20, 2026 03:13
@alice-i-cecile alice-i-cecile added the C-Bug An unexpected or incorrect behavior label Jul 20, 2026

@eswartz eswartz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!


/// Queues a `Send` closure that inserts [`!Send`](Send) data into the app's [`World`].
///
/// Unlike [`insert_non_send`](Self::insert_non_send), `func` is not run immediately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit: it seems like the primary explanation comment shouldn't justify itself against a deprecated method, but instead just make its own case as the following sentences mostly do. (Not to mention there's no "func" to "run immediately" in insert_non_send anyway :)

IMHO the PR description and migration guide explain why this method exists; once the deprecated methods are removed, the comments submitted here should stand alone without editing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-App Bevy apps and plugins C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants