smol-rs / async-executor

Async executor
Apache License 2.0
323 stars 43 forks source link

try_tick considered harmful #88

Open notgull opened 8 months ago

notgull commented 8 months ago

It is my current opinion that try_tick is almost never useful for the purposes that I've seen people use it.

The intended purpose is for FFI interop with other runtimes. Even then it's use case is niche. You almost never want to pop a task off of and not be notified of the next task later. In the worst cases it lends itself to creating a spin loop, where someone polls try_tick in a loop.

Even in the best cases the patterns that it creates are buggy. Here are issues caused by the misuse of the ticking APIs.

For its intended use case of FFI interop, using tick() with a waker that wakes up the event loop that it's in is the preferred option. Even then run() would be the preferred option, as it runs forever.

My intention is as follows:

mintlu8 commented 1 month ago

I think try_tick is pretty useful to make an executor run statefully inside a non-async event loop like winit's.