File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,9 @@ impl App {
187187 /// loop {
188188 /// println!("In main loop");
189189 /// app.update();
190+ /// if let Some(exit) = app.should_exit() {
191+ /// return exit;
192+ /// }
190193 /// }
191194 /// }
192195 ///
Original file line number Diff line number Diff line change @@ -149,7 +149,7 @@ impl Plugin for ScheduleRunnerPlugin {
149149 let base_tick_closure = moved_tick_closure. clone ( ) ;
150150
151151 let tick_app = move || {
152- let mut app = Rc :: get_mut ( & mut app) . unwrap ( ) ;
152+ let app = Rc :: get_mut ( & mut app) . unwrap ( ) ;
153153 let delay = tick ( app, wait) ;
154154 match delay {
155155 Ok ( delay) => set_timeout (
Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ fn my_runner(mut app: App) -> AppExit {
1515 input. 0 = line. unwrap ( ) ;
1616 }
1717 app. update ( ) ;
18+
19+ if let Some ( exit) = app. should_exit ( ) {
20+ return exit;
21+ }
1822 }
1923
2024 AppExit :: Success
@@ -24,10 +28,17 @@ fn print_system(input: Res<Input>) {
2428 println ! ( "You typed: {}" , input. 0 ) ;
2529}
2630
27- fn main ( ) {
31+ fn exit_system ( input : Res < Input > , mut exit_event : EventWriter < AppExit > ) {
32+ if input. 0 == "exit" {
33+ exit_event. send ( AppExit :: Success ) ;
34+ }
35+ }
36+
37+ // AppExit implements `Termination` so we can return it from main.
38+ fn main ( ) -> AppExit {
2839 App :: new ( )
2940 . insert_resource ( Input ( String :: new ( ) ) )
3041 . set_runner ( my_runner)
31- . add_systems ( Update , print_system)
32- . run ( ) ;
42+ . add_systems ( Update , ( print_system, exit_system ) )
43+ . run ( )
3344}
You can’t perform that action at this time.
0 commit comments