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

Non-blocking interface for Timer::wait()? #26

Open
eldruin opened this issue Jun 29, 2020 · 2 comments
Open

Non-blocking interface for Timer::wait()? #26

eldruin opened this issue Jun 29, 2020 · 2 comments
Labels
discussion Something that needs more discussion enhancement New feature or request

Comments

@eldruin
Copy link
Contributor

eldruin commented Jun 29, 2020

I think it could be useful for the Clock::delay() method to have a non-blocking interface like: fn delay<Dur>(dur: Dur) -> nb::Result<(), ()>.
This would return Err(nb::Error::WouldBlock) as long as the delay is ongoing and Ok(()) once finished.

This would give the user more control on polling and what to do while waiting and is the usual interface for other blocking methods (see here for example).

However, I am unsure if it would be possible to implement this in the provided Clock::delay() method implementation since the start would need to be kept constant until completion.

@PTaylor-us
Copy link
Member

Thank you for the issue. I am currently working on the next minor-version release which should include a Timer type. Feel free to take a look at the PR #21 and let me know what you think. It does allow for starting a timer, then either blocking until it expires (wait()) or polling. It also allows reading both elapsed and remaining time (in real-world duration units, of course). In fact, that PR will remove Clock::delay() to use the Timer functionality instead.

@eldruin eldruin mentioned this issue Jun 29, 2020
@PTaylor-us PTaylor-us changed the title Non-blocking interface for Clock::delay()? Non-blocking interface for Timer::wait()? Jul 1, 2020
@PTaylor-us PTaylor-us added discussion Something that needs more discussion enhancement New feature or request labels Jul 4, 2020
@PTaylor-us
Copy link
Member

I'm going to look into this as I have virtually no experience with nb. I'm hesitant to adopt semantics like this due to the uncertainty and deadlock I perceive in the embedded WG. If anything, I may add this alongside the current wait() interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Something that needs more discussion enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants