Skip to content

Commit 2762ec5

Browse files
fix(fs): use smol::block_on for drop handling of File
Ref #766
1 parent 247c94c commit 2762ec5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/fs/file.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::future;
1212
use crate::io::{self, Read, Seek, SeekFrom, Write};
1313
use crate::path::Path;
1414
use crate::prelude::*;
15-
use crate::task::{self, spawn_blocking, Context, Poll, Waker};
15+
use crate::task::{spawn_blocking, Context, Poll, Waker};
1616
use crate::utils::Context as _;
1717

1818
/// An open file on the filesystem.
@@ -315,7 +315,7 @@ impl Drop for File {
315315
// non-blocking fashion, but our only other option here is losing data remaining in the
316316
// write cache. Good task schedulers should be resilient to occasional blocking hiccups in
317317
// file destructors so we don't expect this to be a common problem in practice.
318-
let _ = task::block_on(self.flush());
318+
let _ = smol::block_on(self.flush());
319319
}
320320
}
321321

@@ -867,3 +867,15 @@ impl LockGuard<State> {
867867
Poll::Ready(Ok(()))
868868
}
869869
}
870+
871+
#[cfg(test)]
872+
mod tests {
873+
use super::*;
874+
875+
#[test]
876+
fn async_file_drop() {
877+
crate::task::block_on(async move {
878+
File::open(".").await.unwrap();
879+
});
880+
}
881+
}

0 commit comments

Comments
 (0)