Skip to content

Commit

Permalink
nit: use send rather than try_send in a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier authored and pepyakin committed Aug 24, 2024
1 parent 9ff8125 commit 65aad9a
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions nomt/src/beatree/allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,16 @@ impl AllocatorReader {
}
}

/// Returns the page with the specified page number.
/// Returns the page with the specified page number. Blocks the current thread.
pub fn query(&self, pn: PageNumber) -> Box<Page> {
let page = Box::new(Page::zeroed());

let mut command = Some(IoCommand {
let command = IoCommand {
kind: IoKind::Read(self.store_file.as_raw_fd(), pn.0 as u64, page),
user_data: 0,
});

while let Some(c) = command.take() {
match self.io_handle.try_send(c) {
Ok(()) => break,
Err(TrySendError::Disconnected(_)) => panic!("I/O store worker dropped"),
Err(TrySendError::Full(c)) => {
command = Some(c);
}
}
}
};

self.io_handle.send(command).expect("I/O store worker dropped");

// wait for completion
let completion = self.io_handle.recv().expect("I/O store worker dropped");
Expand Down

0 comments on commit 65aad9a

Please sign in to comment.