Updates
This commit is contained in:
parent
a6981231c1
commit
5942e6a9d5
12 changed files with 186 additions and 148 deletions
|
|
@ -19,9 +19,22 @@ pub fn spawn<N: Display + 'static + Send>(
|
|||
});
|
||||
}
|
||||
|
||||
pub fn spawn_block_in_place<F: FnOnce() -> R, R>(f: F) -> R {
|
||||
// Have this wrapper so that it's easy to switch to just f() when
|
||||
// using tokio's single-threaded runtime. Single-threaded runtime is
|
||||
// easier to read with time profilers.
|
||||
tokio::task::block_in_place(f)
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct BlockingSpawner {
|
||||
allow_tokio_block_in_place: bool,
|
||||
}
|
||||
|
||||
impl BlockingSpawner {
|
||||
pub fn new(allow_tokio_block_in_place: bool) -> Self {
|
||||
Self {
|
||||
allow_tokio_block_in_place,
|
||||
}
|
||||
}
|
||||
pub fn spawn_block_in_place<F: FnOnce() -> R, R>(&self, f: F) -> R {
|
||||
if self.allow_tokio_block_in_place {
|
||||
return tokio::task::block_in_place(f);
|
||||
}
|
||||
|
||||
return f();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue