jonhoo / left-right

A lock-free, read-optimized, concurrency primitive.
Apache License 2.0
1.94k stars 94 forks source link

Adding missing ReadHandleFactory methods #98

Closed iartem closed 3 years ago

iartem commented 3 years ago

It seems ReadHandleFactory couldn't be used previously as there were no respective crate functions exported. Not sure if that's intended though.


This change is Reviewable

codecov[bot] commented 3 years ago

Codecov Report

Merging #98 (ace22ee) into master (8ca7910) will decrease coverage by 0.57%. The diff coverage is 0.00%.

Impacted Files Coverage Δ
src/lib.rs 84.61% <ø> (ø)
src/read/factory.rs 0.00% <0.00%> (ø)
jonhoo commented 3 years ago

Ah, no, the Factory isn't a way to construct a new map, it's a way to get a version of a ReadHandle that you can share across thread boundaries. The idea is that you construct a map somewhere, create a ReadHandleFactory from the ReadHandle, and then stick that ReadHandleFactory in, say, an Arc. Then, in any thread that needs a ReadHandle, you call ReadHandle::handle.

iartem commented 3 years ago

Alright, and how do I create a ReadHandleFactory from the ReadHandle? Correct me if I'm wrong, but everything is pub(crate).

jonhoo commented 3 years ago

You're completely right, seems like a method is indeed missing and I was overly hasty :sweat_smile:. Specifically:

impl ReadHandle {
    pub fn factory(&self) -> ReadHandleFactory {
        ReadHandleFactor {
            inner: Arc::clone(&self.inner),
            epochs: Arc::clone(&self.epochs),
        }
    }
}

Want to submit a PR that adds that method?

iartem commented 3 years ago

Done 😄