Skip to content

Commit

Permalink
fix: using unbuffered I/O for CacheWritingSeqRepo (#119)
Browse files Browse the repository at this point in the history
This makes cache writing for tests more reliable.
  • Loading branch information
holtgrewe authored Jul 25, 2024
1 parent 21e5ab5 commit 5e1731b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::{
collections::HashMap,
fs::{File, OpenOptions},
io::{BufReader, BufWriter},
io::BufReader,
path::Path,
sync::{Arc, Mutex},
};
Expand All @@ -21,7 +21,7 @@ use crate::{
/// Sequence repository reading from actual implementation and writing to a cache.
pub struct CacheWritingSeqRepo {
/// Path to the cache file to write to.
writer: Arc<Mutex<noodles::fasta::Writer<BufWriter<File>>>>,
writer: Arc<Mutex<noodles::fasta::Writer<File>>>,
/// The actual implementation used for reading.
repo: SeqRepo,
/// The internal cache built when writing.
Expand All @@ -47,9 +47,7 @@ impl CacheWritingSeqRepo {
.map_err(|e| Error::SeqSepoCacheOpenWrite(e.to_string()))?;
Ok(Self {
repo,
writer: Arc::new(Mutex::new(noodles::fasta::Writer::new(BufWriter::new(
file,
)))),
writer: Arc::new(Mutex::new(noodles::fasta::Writer::new(file))),
cache,
})
}
Expand Down Expand Up @@ -79,7 +77,8 @@ impl Interface for CacheWritingSeqRepo {
.lock()
.expect("could not acquire lock")
.insert(key.clone(), value.clone());
self.writer
let writer = self
.writer
.lock()
.expect("could not acquire lock")
.write_record(&noodles::fasta::Record::new(
Expand Down

0 comments on commit 5e1731b

Please sign in to comment.