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

feat: add _timeout variants to blocking executions #2912

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wyfo
Copy link

@wyfo wyfo commented Jan 7, 2025

This commit introduce block_on_timeout, as well as LocalPool::run_timeout and LocalPool::run_until_timeout. The internal run_executor has been modified to use either std::thread::park or std::thread::park_timeout. In case of timeout, a TimeoutError instance is returned.

The new generic run_executor_impl returns a Result, which is always Ok in run_executor case (using park). It has been checked with cargo asm that the compiler is able to elide the unwrap call in this case. Also, the assembly showed that the parking closure was inlined, so no regression is expected compared to the previous implementation.

This commit introduce `block_on_timeout`, as well as
`LocalPool::run_timeout` and `LocalPool::run_until_timeout`.
The internal `run_executor` has been modified to use either
`std::thread::park` or `std::thread::park_timeout`. In case of timeout,
a `TimeoutError` instance is returned.

The new generic `run_executor_impl` returns a `Result`, which is
always `Ok` in `run_executor` case (using `park`). It has been
checked with `cargo asm` that the compiler is able to elide the
`unwrap` call in this case. Also, the assembly showed that the
parking closure was inlined, so no regression is expected compared to
the previous implementation.
@wyfo
Copy link
Author

wyfo commented Jan 7, 2025

Resolves #2911

wyfo added 2 commits January 7, 2025 22:17
It allows removing the private field. This pattern is used for example
by `std::thread::AccessError`.
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