Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read data from an other thread #2390

Open
JM-dQ opened this issue Nov 11, 2023 · 3 comments
Open

Read data from an other thread #2390

JM-dQ opened this issue Nov 11, 2023 · 3 comments

Comments

@JM-dQ
Copy link

JM-dQ commented Nov 11, 2023

Hello, I'm learning how to use Druid and I can't find a way of reading the app data from an external thread. I'm looking for something like let data_reader = launcher.get_external_reader(); let data: AppData = data_reader.get_data().

Thanks for your time.

@xStrom
Copy link
Member

xStrom commented Nov 11, 2023

There is no convenient way to directly read data from another thread. What you could do though is send a Command when the need arises, using ExtEventSink. Then on the main thread you will receive this Command and also have access to the app data. The Command payload can contain info you need on what exactly needs to happen. If the external thread needs some data back too, then you need another mechanism on top. For example a channel - where you send the Sender with the Command and listen with the Receiver on the other thread until the main thread handles the Command, processes the data, and sends the results back via the channel.

@ratmice
Copy link
Collaborator

ratmice commented Nov 12, 2023

IIRC when I was writing https://github.com/ratmice/neewerctl/blob/main/src/main.rs it uses the add_idle_callback rather than submit_command. Which is a bit uglier, and I forget exactly why, but there was some reason (some trait bounds that could not be satisfied with the Command approach, I believe).

There are examples of both these approaches in the repository
https://github.com/linebender/druid/blob/master/druid/examples/blocking_function.rs
https://github.com/linebender/druid/blob/master/druid/examples/async_event.rs

@JM-dQ
Copy link
Author

JM-dQ commented Nov 16, 2023

Alr I'll try that thanks for the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants