Skip to content

Commit 6e2c66c

Browse files
committed
DRY
1 parent 6bae741 commit 6e2c66c

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/system.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::util::remove_system;
12
use crate::world::AsyncWorld;
23
use crate::{die, recv_and_yield};
34
use bevy_ecs::prelude::*;
@@ -54,11 +55,7 @@ impl AsyncSystem {
5455
pub async fn unregister(self) {
5556
let Self { id, world } = self;
5657
if let Some(id) = Arc::into_inner(id) {
57-
world
58-
.apply(move |world: &mut World| {
59-
world.remove_system(id).unwrap_or_else(die);
60-
})
61-
.await;
58+
world.apply(remove_system(id)).await;
6259
}
6360
}
6461
}
@@ -148,11 +145,7 @@ impl<I: Send + 'static, O: Send + 'static> AsyncIOSystem<I, O> {
148145
pub async fn unregister(self) {
149146
let Self { id, world, _pd } = self;
150147
if let Some(id) = Arc::into_inner(id) {
151-
world
152-
.apply(move |world: &mut World| {
153-
world.remove_system(id).unwrap_or_else(die);
154-
})
155-
.await
148+
world.apply(remove_system(id)).await
156149
}
157150
}
158151
}

src/util.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bevy_ecs::prelude::*;
2-
use bevy_ecs::system::Command;
2+
use bevy_ecs::system::{Command, SystemId};
33

44
pub(crate) fn insert<B: Bundle>(id: Entity, bundle: B) -> impl Command {
55
move |world: &mut World| {
@@ -24,3 +24,9 @@ pub(crate) fn remove_resource<R: Resource>() -> impl Command {
2424
world.remove_resource::<R>();
2525
}
2626
}
27+
28+
pub(crate) fn remove_system<I: 'static, O: 'static>(system_id: SystemId<I, O>) -> impl Command {
29+
move |world: &mut World| {
30+
world.remove_system(system_id).ok();
31+
}
32+
}

0 commit comments

Comments
 (0)