-
Notifications
You must be signed in to change notification settings - Fork 80
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
add async support using bisync crate #176
base: develop
Are you sure you want to change the base?
Conversation
d7ba16b
to
8c5f264
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An interesting approach! I want to dig into the docs in more detail but it seems workable - modulo that AFIT feature-flag that has appeared.
It might also be good to move the example import renames to another PR to keep this one cleaner so we can see precisely only that which is affected by the async additions. |
That goes towards a bigger question: do you want to break the public API by moving the existing API into a new There's the whole blocking API of the crate, then the I think this would be rather confusing. It's difficult to even tell that I clicked a link and navigated to another page because it looks so similar to the documentation's front page. By moving the existing API into a |
I've avoided running |
I had to use the The other places I used |
Yes, leaking a file handle means you can't reopen it, and handles are a finite resource. Plus certain context is only written to disk on file close so the disk ends up needing a fsck/scandisk pass. As long as that only affects the async users that's fine. Moving the blocking API into the blocking module is fine with me. |
Can you rebase? #177 might make this smaller. |
Is it possible to give the async version a blocking drop? Better than doing nothing. |
d75eb0f
to
de430ba
Compare
Okay, rebased.
Unfortunately not. That would require this crate to bring in its own async executor and set that up just within |
This moves the existing API into a `blocking` module and duplicates the API into a new `asynchronous` module, using `async fn` where applicable. Fixes rust-embedded-community#50
Is there no no_std block_on! ? Can't you just spin polling the Future? |
I just found embassy_futures::block_on, however, I don't think it's a good idea to use it to impl Drop for async Files/Volumes. We can't know if a user would want that and there's no way to opt out of Drop::drop getting called if it's implemented. For example, the user could have strict power consumption requirements that require putting the MCU to sleep on every |
But it's probably better than a corrupt file system, and any correct program will close them asynchronously before dropping. What do other async File APIs do? |
impl Drop for File in async-std: impl Drop for File {
fn drop(&mut self) {
// We need to flush the file on drop. Unfortunately, that is not possible to do in a
// non-blocking fashion, but our only other option here is losing data remaining in the
// write cache. Good task schedulers should be resilient to occasional blocking hiccups in
// file destructors so we don't expect this to be a common problem in practice.
let _ = futures_lite::future::block_on(self.flush());
}
} Suggestion: impl Drop for async File/Volume using |
Nevermind, I forgot |
This moves the existing API into a
blocking
module and duplicates the API into a newasynchronous
module, usingasync fn
where applicable. This uses the bisync crate rather than maybe_async used by #154. This involved moving everything in the src directory into a new src/inner directory, then exposing blocking/async versions via how they are imported in src/lib.rs.I think this resolves the concerns brought up in #154: sync and async can both be built at the same time, usage of bisync by other crates in the dependency graph doesn't affect this, and changes to the example and test code are minimal (just adjusting import path).
I moved submodules that have no difference between blocking & async to a new
common
module. That code gets re-exported under theblocking
/asynchronous
modules in the same relative path in the module hierarchy as before. There may be opportunities to split more code into that common module, but I have tried to keep changes to a minimum for now to make it easier to review.I have not added Cargo features for sync/async; they're both built. If requested, I could put each behind a feature gate, though I don't think it's necessary.
Fixes #50