Skip to content

Commit d46364c

Browse files
authored
Merge pull request #299 from async-rs/blocking-updates
Blocking updates
2 parents 237cfa0 + 33806ad commit d46364c

33 files changed

+56
-56
lines changed

src/fs/canonicalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ use crate::task::blocking;
3232
/// ```
3333
pub async fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
3434
let path = path.as_ref().to_owned();
35-
blocking::spawn(async move { std::fs::canonicalize(&path).map(Into::into) }).await
35+
blocking::spawn(move || std::fs::canonicalize(&path).map(Into::into)).await
3636
}

src/fs/copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ use crate::task::blocking;
4141
pub async fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
4242
let from = from.as_ref().to_owned();
4343
let to = to.as_ref().to_owned();
44-
blocking::spawn(async move { std::fs::copy(&from, &to) }).await
44+
blocking::spawn(move || std::fs::copy(&from, &to)).await
4545
}

src/fs/create_dir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ use crate::task::blocking;
3434
/// ```
3535
pub async fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
3636
let path = path.as_ref().to_owned();
37-
blocking::spawn(async move { std::fs::create_dir(path) }).await
37+
blocking::spawn(move || std::fs::create_dir(path)).await
3838
}

src/fs/create_dir_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ use crate::task::blocking;
2929
/// ```
3030
pub async fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
3131
let path = path.as_ref().to_owned();
32-
blocking::spawn(async move { std::fs::create_dir_all(path) }).await
32+
blocking::spawn(move || std::fs::create_dir_all(path)).await
3333
}

src/fs/dir_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl DirBuilder {
108108
}
109109

110110
let path = path.as_ref().to_owned();
111-
async move { blocking::spawn(async move { builder.create(path) }).await }
111+
async move { blocking::spawn(move || builder.create(path)).await }
112112
}
113113
}
114114

src/fs/dir_entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl DirEntry {
8989
/// ```
9090
pub async fn metadata(&self) -> io::Result<Metadata> {
9191
let inner = self.0.clone();
92-
blocking::spawn(async move { inner.metadata() }).await
92+
blocking::spawn(move || inner.metadata()).await
9393
}
9494

9595
/// Reads the file type for this entry.
@@ -127,7 +127,7 @@ impl DirEntry {
127127
/// ```
128128
pub async fn file_type(&self) -> io::Result<FileType> {
129129
let inner = self.0.clone();
130-
blocking::spawn(async move { inner.file_type() }).await
130+
blocking::spawn(move || inner.file_type()).await
131131
}
132132

133133
/// Returns the bare name of this entry without the leading path.

src/fs/file.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl File {
9797
/// ```
9898
pub async fn open<P: AsRef<Path>>(path: P) -> io::Result<File> {
9999
let path = path.as_ref().to_owned();
100-
let file = blocking::spawn(async move { std::fs::File::open(&path) }).await?;
100+
let file = blocking::spawn(move || std::fs::File::open(&path)).await?;
101101
Ok(file.into())
102102
}
103103

@@ -132,7 +132,7 @@ impl File {
132132
/// ```
133133
pub async fn create<P: AsRef<Path>>(path: P) -> io::Result<File> {
134134
let path = path.as_ref().to_owned();
135-
let file = blocking::spawn(async move { std::fs::File::create(&path) }).await?;
135+
let file = blocking::spawn(move || std::fs::File::create(&path)).await?;
136136
Ok(file.into())
137137
}
138138

@@ -165,7 +165,7 @@ impl File {
165165
})
166166
.await?;
167167

168-
blocking::spawn(async move { state.file.sync_all() }).await
168+
blocking::spawn(move || state.file.sync_all()).await
169169
}
170170

171171
/// Synchronizes OS-internal buffered contents to disk.
@@ -201,7 +201,7 @@ impl File {
201201
})
202202
.await?;
203203

204-
blocking::spawn(async move { state.file.sync_data() }).await
204+
blocking::spawn(move || state.file.sync_data()).await
205205
}
206206

207207
/// Truncates or extends the file.
@@ -234,7 +234,7 @@ impl File {
234234
})
235235
.await?;
236236

237-
blocking::spawn(async move { state.file.set_len(size) }).await
237+
blocking::spawn(move || state.file.set_len(size)).await
238238
}
239239

240240
/// Reads the file's metadata.
@@ -253,7 +253,7 @@ impl File {
253253
/// ```
254254
pub async fn metadata(&self) -> io::Result<Metadata> {
255255
let file = self.file.clone();
256-
blocking::spawn(async move { file.metadata() }).await
256+
blocking::spawn(move || file.metadata()).await
257257
}
258258

259259
/// Changes the permissions on the file.
@@ -282,7 +282,7 @@ impl File {
282282
/// ```
283283
pub async fn set_permissions(&self, perm: Permissions) -> io::Result<()> {
284284
let file = self.file.clone();
285-
blocking::spawn(async move { file.set_permissions(perm) }).await
285+
blocking::spawn(move || file.set_permissions(perm)).await
286286
}
287287
}
288288

@@ -702,7 +702,7 @@ impl LockGuard<State> {
702702
self.register(cx);
703703

704704
// Start a read operation asynchronously.
705-
blocking::spawn(async move {
705+
blocking::spawn(move || {
706706
// Read some data from the file into the cache.
707707
let res = {
708708
let State { file, cache, .. } = &mut *self;
@@ -811,7 +811,7 @@ impl LockGuard<State> {
811811
self.register(cx);
812812

813813
// Start a write operation asynchronously.
814-
blocking::spawn(async move {
814+
blocking::spawn(move || {
815815
match (&*self.file).write_all(&self.cache) {
816816
Ok(_) => {
817817
// Switch to idle mode.
@@ -844,7 +844,7 @@ impl LockGuard<State> {
844844
self.register(cx);
845845

846846
// Start a flush operation asynchronously.
847-
blocking::spawn(async move {
847+
blocking::spawn(move || {
848848
match (&*self.file).flush() {
849849
Ok(()) => {
850850
// Mark the file as flushed.

src/fs/hard_link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ use crate::task::blocking;
3232
pub async fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
3333
let from = from.as_ref().to_owned();
3434
let to = to.as_ref().to_owned();
35-
blocking::spawn(async move { std::fs::hard_link(&from, &to) }).await
35+
blocking::spawn(move || std::fs::hard_link(&from, &to)).await
3636
}

src/fs/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::task::blocking;
3636
/// ```
3737
pub async fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
3838
let path = path.as_ref().to_owned();
39-
blocking::spawn(async move { std::fs::metadata(path) }).await
39+
blocking::spawn(move || std::fs::metadata(path)).await
4040
}
4141

4242
cfg_if! {

src/fs/open_options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl OpenOptions {
285285
pub fn open<P: AsRef<Path>>(&self, path: P) -> impl Future<Output = io::Result<File>> {
286286
let path = path.as_ref().to_owned();
287287
let options = self.0.clone();
288-
async move { blocking::spawn(async move { options.open(path).map(|f| f.into()) }).await }
288+
async move { blocking::spawn(move || options.open(path).map(|f| f.into())).await }
289289
}
290290
}
291291

0 commit comments

Comments
 (0)