Problem with async external events: ExtEventSink
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9.7k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
The example code /druid/examples/async_event.rs has this problem, if you are using tokio instead of threads. Try logging the color_clone in front of the `event_sink.add_idle_callback` call and in function supplied to the `event_sink.add_idle_callback` call.
Some events triggered via add_idle_callback - if they are early enough - are ignored. This happens probably because the launcher wasn't yet launched with `launcher.launch(Color::Black)`.
There are two solutions for this problem:
- Create an `launcher..spawn(event_handler_func: fn (event_sink: ExtEventSink)` method to add external event sinks. The Function is called, when the `launcher.launch` is called.
- Handle `event_sink.add_idle_callback` which were added before `launcher.launch`
My current *hacky* solution is to wait three seconds before calling the event handler:
```rust
let event_sink = launcher.get_external_handle();
task::spawn(async move {
time::sleep(Duration::from_secs(3)).await; // Hack
handle_events(event_sink).await;
});
```
I'm using tokio so task instead of thread is called here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with druid/examples/async_event.rs and trace ExtEventSink.add_idle_callback around launcher.launch(Color::Black), reproducing the behavior with tokio rather than threads. Compare the logged color_clone values before launch and inside the callback; done means callbacks registered before launch are no longer ignored or the supported launch-time handling is clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100