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

src/fs/read.rs

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

src/fs/read_dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use crate::task::{blocking, Context, JoinHandle, Poll};
4545
/// ```
4646
pub async fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
4747
let path = path.as_ref().to_owned();
48-
blocking::spawn(async move { std::fs::read_dir(path) })
48+
blocking::spawn(move || std::fs::read_dir(path))
4949
.await
5050
.map(ReadDir::new)
5151
}
@@ -91,7 +91,7 @@ impl Stream for ReadDir {
9191
let mut inner = opt.take().unwrap();
9292

9393
// Start the operation asynchronously.
94-
self.0 = State::Busy(blocking::spawn(async move {
94+
self.0 = State::Busy(blocking::spawn(move || {
9595
let next = inner.next();
9696
(inner, next)
9797
}));

src/fs/read_link.rs

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

src/fs/read_to_string.rs

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

src/fs/remove_dir.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 remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
3131
let path = path.as_ref().to_owned();
32-
blocking::spawn(async move { std::fs::remove_dir(path) }).await
32+
blocking::spawn(move || std::fs::remove_dir(path)).await
3333
}

src/fs/remove_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 remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
3131
let path = path.as_ref().to_owned();
32-
blocking::spawn(async move { std::fs::remove_dir_all(path) }).await
32+
blocking::spawn(move || std::fs::remove_dir_all(path)).await
3333
}

src/fs/remove_file.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 remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
3131
let path = path.as_ref().to_owned();
32-
blocking::spawn(async move { std::fs::remove_file(path) }).await
32+
blocking::spawn(move || std::fs::remove_file(path)).await
3333
}

src/fs/rename.rs

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

src/fs/set_permissions.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 set_permissions<P: AsRef<Path>>(path: P, perm: Permissions) -> io::Result<()> {
3434
let path = path.as_ref().to_owned();
35-
blocking::spawn(async move { std::fs::set_permissions(path, perm) }).await
35+
blocking::spawn(move || std::fs::set_permissions(path, perm)).await
3636
}

src/fs/symlink_metadata.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 symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
3636
let path = path.as_ref().to_owned();
37-
blocking::spawn(async move { std::fs::symlink_metadata(path) }).await
37+
blocking::spawn(move || std::fs::symlink_metadata(path)).await
3838
}

src/fs/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ use crate::task::blocking;
3333
pub async fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> {
3434
let path = path.as_ref().to_owned();
3535
let contents = contents.as_ref().to_owned();
36-
blocking::spawn(async move { std::fs::write(path, contents) }).await
36+
blocking::spawn(move || std::fs::write(path, contents)).await
3737
}

src/io/stderr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Write for Stderr {
116116
inner.buf[..buf.len()].copy_from_slice(buf);
117117

118118
// Start the operation asynchronously.
119-
*state = State::Busy(blocking::spawn(async move {
119+
*state = State::Busy(blocking::spawn(move || {
120120
let res = std::io::Write::write(&mut inner.stderr, &inner.buf);
121121
inner.last_op = Some(Operation::Write(res));
122122
State::Idle(Some(inner))
@@ -144,7 +144,7 @@ impl Write for Stderr {
144144
let mut inner = opt.take().unwrap();
145145

146146
// Start the operation asynchronously.
147-
*state = State::Busy(blocking::spawn(async move {
147+
*state = State::Busy(blocking::spawn(move || {
148148
let res = std::io::Write::flush(&mut inner.stderr);
149149
inner.last_op = Some(Operation::Flush(res));
150150
State::Idle(Some(inner))

src/io/stdin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Stdin {
119119
let mut inner = opt.take().unwrap();
120120

121121
// Start the operation asynchronously.
122-
*state = State::Busy(blocking::spawn(async move {
122+
*state = State::Busy(blocking::spawn(move || {
123123
inner.line.clear();
124124
let res = inner.stdin.read_line(&mut inner.line);
125125
inner.last_op = Some(Operation::ReadLine(res));
@@ -172,7 +172,7 @@ impl Read for Stdin {
172172
}
173173

174174
// Start the operation asynchronously.
175-
*state = State::Busy(blocking::spawn(async move {
175+
*state = State::Busy(blocking::spawn(move || {
176176
let res = std::io::Read::read(&mut inner.stdin, &mut inner.buf);
177177
inner.last_op = Some(Operation::Read(res));
178178
State::Idle(Some(inner))

src/io/stdout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Write for Stdout {
116116
inner.buf[..buf.len()].copy_from_slice(buf);
117117

118118
// Start the operation asynchronously.
119-
*state = State::Busy(blocking::spawn(async move {
119+
*state = State::Busy(blocking::spawn(move || {
120120
let res = std::io::Write::write(&mut inner.stdout, &inner.buf);
121121
inner.last_op = Some(Operation::Write(res));
122122
State::Idle(Some(inner))
@@ -144,7 +144,7 @@ impl Write for Stdout {
144144
let mut inner = opt.take().unwrap();
145145

146146
// Start the operation asynchronously.
147-
*state = State::Busy(blocking::spawn(async move {
147+
*state = State::Busy(blocking::spawn(move || {
148148
let res = std::io::Write::flush(&mut inner.stdout);
149149
inner.last_op = Some(Operation::Flush(res));
150150
State::Idle(Some(inner))

src/net/addr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl ToSocketAddrs for (&str, u16) {
196196
}
197197

198198
let host = host.to_string();
199-
let task = blocking::spawn(async move {
199+
let task = blocking::spawn(move || {
200200
std::net::ToSocketAddrs::to_socket_addrs(&(host.as_str(), port))
201201
});
202202
ToSocketAddrsFuture::Resolving(task)
@@ -217,8 +217,7 @@ impl ToSocketAddrs for str {
217217
}
218218

219219
let addr = self.to_string();
220-
let task =
221-
blocking::spawn(async move { std::net::ToSocketAddrs::to_socket_addrs(addr.as_str()) });
220+
let task = blocking::spawn(move || std::net::ToSocketAddrs::to_socket_addrs(addr.as_str()));
222221
ToSocketAddrsFuture::Resolving(task)
223222
}
224223
}

src/net/tcp/stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl TcpStream {
7676
let mut last_err = None;
7777

7878
for addr in addrs.to_socket_addrs().await? {
79-
let res = blocking::spawn(async move {
79+
let res = blocking::spawn(move || {
8080
let std_stream = std::net::TcpStream::connect(addr)?;
8181
let mio_stream = mio::net::TcpStream::from_stream(std_stream)?;
8282
Ok(TcpStream {

src/os/unix/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::task::blocking;
2828
pub async fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
2929
let src = src.as_ref().to_owned();
3030
let dst = dst.as_ref().to_owned();
31-
blocking::spawn(async move { std::os::unix::fs::symlink(&src, &dst) }).await
31+
blocking::spawn(move || std::os::unix::fs::symlink(&src, &dst)).await
3232
}
3333

3434
cfg_if! {

src/os/unix/net/datagram.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl UnixDatagram {
6767
/// ```
6868
pub async fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixDatagram> {
6969
let path = path.as_ref().to_owned();
70-
let socket = blocking::spawn(async move { mio_uds::UnixDatagram::bind(path) }).await?;
70+
let socket = blocking::spawn(move || mio_uds::UnixDatagram::bind(path)).await?;
7171
Ok(UnixDatagram::new(socket))
7272
}
7373

src/os/unix/net/listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl UnixListener {
6868
/// ```
6969
pub async fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
7070
let path = path.as_ref().to_owned();
71-
let listener = blocking::spawn(async move { mio_uds::UnixListener::bind(path) }).await?;
71+
let listener = blocking::spawn(move || mio_uds::UnixListener::bind(path)).await?;
7272

7373
Ok(UnixListener {
7474
watcher: Watcher::new(listener),

src/os/unix/net/stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl UnixStream {
5858
pub async fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
5959
let path = path.as_ref().to_owned();
6060

61-
blocking::spawn(async move {
61+
blocking::spawn(move || {
6262
let std_stream = std::os::unix::net::UnixStream::connect(path)?;
6363
let mio_stream = mio_uds::UnixStream::from_stream(std_stream)?;
6464
Ok(UnixStream {

src/task/block_on.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use kv_log_macro::trace;
1919
/// Calling this function is similar to [spawning] a thread and immediately [joining] it, except an
2020
/// asynchronous task will be spawned.
2121
///
22-
/// See also: [`task::blocking`].
22+
/// See also: [`task::spawn_blocking`].
2323
///
24-
/// [`task::blocking`]: fn.blocking.html
24+
/// [`task::spawn_blocking`]: fn.spawn_blocking.html
2525
///
2626
/// [spawning]: https://doc.rust-lang.org/std/thread/fn.spawn.html
2727
/// [joining]: https://doc.rust-lang.org/std/thread/struct.JoinHandle.html#method.join

0 commit comments

Comments
 (0)