Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Created December 9, 2023 15:14
Show Gist options
  • Save stepancheg/0b4cd6d2e62363ef5470bc156ec59220 to your computer and use it in GitHub Desktop.
Save stepancheg/0b4cd6d2e62363ef5470bc156ec59220 to your computer and use it in GitHub Desktop.
use std::thread;
use std::time::Duration;
use bevy::app::App;
use bevy::prelude::*;
use rand::Rng;
#[derive(Resource, Default)]
struct MyRes;
fn first() {
println!("first");
}
fn random_delay1() {
thread::sleep(Duration::from_millis(rand::thread_rng().gen_range(0..10)))
}
fn random_delay2() {
thread::sleep(Duration::from_millis(rand::thread_rng().gen_range(0..10)))
}
fn system1(_my_res: ResMut<MyRes>) {
println!("system1");
}
fn system2(_my_res: ResMut<MyRes>) {
println!("system2");
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.init_resource::<MyRes>()
.add_systems(
Update,
(
first,
random_delay1.after(first),
system1.after(random_delay1),
random_delay2.after(first),
system2.after(random_delay2),
),
)
.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment