PistonDevelopers / piston

A modular game engine written in Rust
https://www.piston.rs
MIT License
4.62k stars 234 forks source link

Provide async iterator for event loop #1392

Closed j-hui closed 5 months ago

j-hui commented 1 year ago

I'm hoping to integrate the piston event loop with some other async code. Is this a feature you would consider supporting?

As a proof-of-concept, I implemented this, with only two lines of change to the next() function; one to replace the use of spin_sleep with tokio::time::sleep, and one to declare the next() function async.

I have two questions about this:

  1. Are there any pitfalls I'm missing here?
  2. Considering the changes needed are so small, would you consider adding async support to your event_loop, to avoid my duplicating that code?
bvssvni commented 1 year ago

Can you elaborate on the motivation for using an async event loop? Are there any tradeoffs?

bvssvni commented 10 months ago

I added an "async" feature and published 0.55.0: https://crates.io/crates/piston/0.55.0

You call async_next instead of next.

We will try it out for a while and collect feedback.

bvssvni commented 10 months ago

I added an "async_test" example to the OpenGL graphics backend: https://github.com/PistonDevelopers/opengl_graphics/pull/340

bvssvni commented 5 months ago

There seems to be no problems supporting async. However, it will remain behind a feature flag "async" since most users don't need it.

Closing.