antoyo / relm

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
MIT License
2.41k stars 79 forks source link

relm's event don't work when in a busy loop in the gtk GUI thread even if calling process_events #281

Open emmanueltouzery opened 3 years ago

emmanueltouzery commented 3 years ago

see reproduction here: https://github.com/emmanueltouzery/relm_process_events

the code adds 100k rows in a gtk treeview. It does so through a busy loop in the gtk GUI thread. BUT it doesn't freeze the GUI thread because it regularly calls:

                while gtk::events_pending() {
                    gtk::main_iteration();
                }

however that is not enough apparently to enable relm's event processing. It seems relm components' update() methods are called only after such a busy loop. In this repro, I listen to double clicks on grid rows. When there is such a double click, I make a println!()... this works during the busy loop:

[src/main.rs:46] i = 65398 [src/main.rs:46] i = 65399 [src/main.rs:46] i = 65400 emitting relm event [src/main.rs:46] i = 65401 [src/main.rs:46] i = 65402

however the update() itself, that should be called as a result of the stream().emit() being invoked, is not invoked until after the busy loop finishes:

    fn update(&mut self, event: Msg) {
        dbg!(event);
    }

[src/main.rs:46] i = 99997 [src/main.rs:46] i = 99998 [src/main.rs:46] i = 99999 emitting relm event [src/main.rs:69] event = RowClicked emitting relm event [src/main.rs:69] event = RowClicked emitting relm event [src/main.rs:69] event = RowClicked

antoyo commented 2 years ago

Sorry, I thought I had answered this question. It seems like a bug indeed. I don't have much time to debug this currently, but if you're willing, you could start by looking at whether those functions are called during the busy loop.