Skip to content

Commit

Permalink
final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Arruda committed Mar 12, 2021
1 parent 48ac7f2 commit 1a6aa95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,6 @@ hard drive. This means that some major API changes took place:
* You can also just _try_ to receive items, without the need to `.await` anything. For
each fo the receiving methods `recv`, `recv_batch` and `recv_until` you now have the
try versions: `try_recv`, `try_recv_batch`, `try_recv_until`.
* Solved a bug regarding the rollback of batch transactions when crossing over a segment.
Older versions will do a complete mess out of this. The side effect: `commit` now returns
a `Result`, which has to be treated.
11 changes: 10 additions & 1 deletion src/queue/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ pub(crate) async fn acquire_recv_lock<P: AsRef<Path>>(base: P) -> io::Result<Fil
/// The receiver part of the queue. This part is asynchronous and therefore
/// needs an executor that will the poll the futures to completion.
pub struct Receiver {
/// The path to the folder holding the queue.
base: PathBuf,
/// The acquired receiver lock file for this queue.
_file_guard: FileGuard,
/// The current segment being tailed.
tail_follower: TailFollower,
/// The last header read from the queue.
maybe_header: Option<[u8; 4]>,
/// The current queue state.
state: QueueState,
/// The queue state as it was in the begining of the current transaction.
initial_state: QueueState,
base: PathBuf,
/// The queue state saver/loader.
persistence: QueueStatePersistence,
/// Use this queue to buffer elements and provide "atomicity in an
/// asynchronous context".
Expand Down Expand Up @@ -501,6 +508,7 @@ impl Receiver {
predicate(None).await;

// Poor man's do-while (aka. until)
// Strategy: fill `read_and_unused` to the brim and then drain at the end.
loop {
// Need to fetch from disk?
if n_read == self.read_and_unused.len() {
Expand All @@ -518,6 +526,7 @@ impl Receiver {

// And now, drain!
let data = self.drain(n_read);

Ok(RecvGuard {
receiver: self,
item: Some(data),
Expand Down

0 comments on commit 1a6aa95

Please sign in to comment.