smol-rs / smol-rs/async-executor
try_tick considered harmful
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 459
- Forks
- 52
- Avg merge
- 6h 53m
- Merged PRs (30d)
- 1
Description
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.
- https://github.com/orgs/smol-rs/discussions/298
- https://github.com/smol-rs/async-executor/issues/44
- No doubt constant misuses of this function in production code that is never reported.
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:
- Mark
try_tickas deprecated. - In the next breaking release of
async-executorremovetry_tick. - Specify in documentation that
runis the preferred way of driving the executor. - Specify in the documentation that
tickandtry_tickare exclusively used in executor interop, and that puresmoluse cases should userun().
Contributor guide
No contributing guide indexed for this repository
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 by reviewing the public try_tick, tick, and run APIs, then read the linked discussions and async-executor issue for reported misuse. Done means try_tick is deprecated, the documentation presents run as the preferred driver, and clarifies that tick and try_tick are for executor interop; removal is planned for the next breaking release.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100