iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
24.94k stars 1.18k forks source link

Threaded message loop #813

Closed Yuri6037 closed 3 years ago

Yuri6037 commented 3 years ago

I have an application which runs a SLOW process. By slow it means this process contains downloads, unzipping, file copy, folder recursive copy, WinAPI registry calls and a lot of file operations. Sometimes this process may even be blocking in wait of user input.

I need to write a GUI interface for this software. Considering how slow the process may be, I decided it probably is better to offline it to a secondary background thread separated from the rendering thread. The process in question of course is independent of it's interface it dialogs through a trait so surely this trait can be implemented as a mutex queue or if Rust permits it a memory barrier based circular buffer.

My problem is I cannot find any API in iced to post a message from a background thread or any other part of the code except the window itself. Currently my only idea is to hack a timer based on the clock but a timer that would trigger every micro second or milisecond and poll all messages from the background thread in this timer.

EDIT: The code MUST work under iced 0.2.0 because the newer version is broken; it fails to compile throwing

error[E0658]: use of unstable library feature 'future_readiness_fns'
  --> /home/X/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.7.1/src/backend/direct.rs:17:14
   |
17 |     future::{ready, Ready},
   |              ^^^^^
   |
   = note: see issue #70921 <https://github.com/rust-lang/rust/issues/70921> for more information

Is there any better way or official API to deal with posting arbitary types of messages back to the window view function?

Yuri6037 commented 3 years ago

I have openned a new issue related to the requirement of Debug to the message type.

My current approach is using a subscription.