Skip to content

Commit

Permalink
tokio spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
numinnex committed Nov 16, 2024
1 parent 83d4346 commit 7f921b4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions server/src/streaming/direct_io/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,20 @@ impl DirectIOStorage {
}

pub async fn write_batches(&self, file_path: &str, bytes: Vec<u8>) -> Result<u32, IggyError> {
let mut std_file = std::fs::File::options().append(true).custom_flags(libc::O_DIRECT).open(file_path)?;
//let mut file = OpenOptions::new().append(true).custom_flags(libc::O_DIRECT).open(file_path).await?;
let size = bytes.len() as _;
spawn_blocking(move || {
if let Err(e) = std_file.write_all(&bytes) {
warn!("error writing: {}", e);
}
}).await.unwrap();
let std_file = std::fs::File::options().append(true).custom_flags(libc::O_DIRECT).open(file_path).unwrap();
let handle = tokio::spawn(async move{
Self::foo(std_file, bytes).await;
});
std::mem::forget(handle);

Ok(size)
}

async fn foo(mut file: std::fs::File, bytes: Vec<u8>) {
if let Err(e) = file.write_all(&bytes) {
warn!("error writing: {}", e);
}
}
}

0 comments on commit 7f921b4

Please sign in to comment.