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

Queueing async and sync functions on the main thread #114

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

quickdudley
Copy link

In response to #55

Two new methods in UI:

  1. async_context creates a token (iui::concurrent::Context) which can serve as evidence that UI::init() has run successfully; this token is Send
  2. spawn schedules an async function or future on the main thread. Since it's a method in UI it can only be run in the main thread. It returns control to the main loop when it blocks and queues itself again when it's ready again.

Two methods in concurrent::Context

  1. queue_main behaves like UI::queue_main in that it schedules a closure or function to run on the main thread. Unlike UI::queue_main it can be run in other threads but requires the closure to be Send.
  2. spawn behaves like UI::spawn but can be run from other threads; requires the future to be Send

Using UI::spawn and an async channel such as provided by tokio::sync::mpsc we can wait for things to happen on other threads without busy waiting or blocking other events and then update our widgets accordingly.

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

Successfully merging this pull request may close these issues.

1 participant