-
Notifications
You must be signed in to change notification settings - Fork 24
To use nb or not to use nb #11
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
Comments
Very strong 👎 against using It is impossible to implement traits using Consider an API like this: fn read(&mut self, address: u32, bytes: &mut [u8]) -> nb::Result<(), Self::Error> { .. } On first call, this would start the DMA read into To allow DMA implementations, the API would have to look like this: // on NorFlash
fn read<'a>(&'a mut self, address: u32, bytes: &'a mut [u8]) -> Transfer<'a> { .. }
// on Transfer
fn is_done(&mut self) -> bool;
fn wait_done(&mut self); The key is that Transfer borrows Or, alternatively, a Futures-based API fn read<'a>(&'a mut self, address: u32, bytes: &'a mut [u8]) -> impl Future<Output=Result<(), Error>> + 'a { .. } The problem is a trait with either of these APIs (Transfer or Future) requires GATs (due to the generic lifetime), so they're nightly-only for now. Embassy has such a trait here. |
So as i read what @Dirbaio is saying, it would make sense to make a regular blocking |
With how usable async is has become since this issue was raised, shall we resolve it as "we'll only have blocking and async"? |
IMO yes |
Quote from @MathiasKoch in #9:
Let's discuss this here for clarity.
Personally I am unsure about this. On the one hand writes can be extremely slow, so having some kind of asynchronicity would be nice and it is just as easy for implementors to write synchronous code with
nb
.On the other hand it is a little bit more effort for users, because they have to wrap everything in
block!(...)
if they want it to be synchronous and I imagine it is extremely hard to write an agnostic asynchronous driver. So I am not sure if this possibility will be used in practice.Maybe we could add a
nb
variant later alongside the current version. Or we could change it tonb
now and provide blanket implementations that just callblock!()
.The text was updated successfully, but these errors were encountered: