Skip to content

Commit

Permalink
Make blocking configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Apr 1, 2022
1 parent b3e873a commit e1825cd
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions parquet/src/arrow/async_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,31 +133,40 @@ impl Storage for Box<dyn Storage> {

pub struct FileStorage {
file: Option<File>,
spawn_blocking: bool,
}
impl FileStorage {
pub fn new(file: File) -> Self {
Self { file: Some(file) }
pub fn new(file: File, spawn_blocking: bool) -> Self {
Self {
file: Some(file),
spawn_blocking,
}
}

pub async fn asyncify<F, T>(&mut self, f: F) -> Result<T>
where
F: FnOnce(&mut File) -> Result<T> + Send + 'static,
T: Send + 'static,
{
// let mut file = self.file.take().expect("FileStorage poisoned");
// let (file, result) = tokio::task::spawn_blocking(move || {
// let result = f(&mut file);
// (file, result)
// })
// .await
// .expect("background task panicked");
//
// self.file = Some(file);
// result

// TODO: Temporary use blocking file IO in tokio worker
let file = self.file.as_mut().unwrap();
f(file)
match self.spawn_blocking {
true => {
let mut file = self.file.take().expect("FileStorage poisoned");
let (file, result) = tokio::task::spawn_blocking(move || {
let result = f(&mut file);
(file, result)
})
.await
.expect("background task panicked");

self.file = Some(file);
result
}
false => {
// Use blocking file IO in tokio worker
let file = self.file.as_mut().unwrap();
f(file)
}
}
}
}

Expand Down

0 comments on commit e1825cd

Please sign in to comment.