mirror of
https://github.com/async-rs/async-std.git
synced 2025-03-29 04:26:41 +00:00
Merge pull request #768 from async-rs/fix/file-block
fix(fs): use smol::block_on for drop handling of File
This commit is contained in:
commit
e20b0f0d75
1 changed files with 14 additions and 2 deletions
|
@ -12,7 +12,7 @@ use crate::future;
|
||||||
use crate::io::{self, Read, Seek, SeekFrom, Write};
|
use crate::io::{self, Read, Seek, SeekFrom, Write};
|
||||||
use crate::path::Path;
|
use crate::path::Path;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::task::{self, spawn_blocking, Context, Poll, Waker};
|
use crate::task::{spawn_blocking, Context, Poll, Waker};
|
||||||
use crate::utils::Context as _;
|
use crate::utils::Context as _;
|
||||||
|
|
||||||
/// An open file on the filesystem.
|
/// An open file on the filesystem.
|
||||||
|
@ -315,7 +315,7 @@ impl Drop for File {
|
||||||
// non-blocking fashion, but our only other option here is losing data remaining in the
|
// 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
|
// 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.
|
// file destructors so we don't expect this to be a common problem in practice.
|
||||||
let _ = task::block_on(self.flush());
|
let _ = smol::block_on(self.flush());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,3 +867,15 @@ impl LockGuard<State> {
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn async_file_drop() {
|
||||||
|
crate::task::block_on(async move {
|
||||||
|
File::open(file!()).await.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue