-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add logic for replicating writes and reads to stores #20
Conversation
/** | ||
* Replicates writes to both stores, and uses the "or" logic defined on ReadableStore to replicate reads. | ||
*/ | ||
def combinedWith(other: Store[Self, K, V]): Store[Self, K, V] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we do this with a Seq[Store]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a combine
method to the companion object that does this with a seq, then have this method call Store.combine(Seq(this, other))
/** | ||
* Replicates writes to all stores, and takes the first successful read. | ||
*/ | ||
def replicate[Self <: Store[Self, K, V], K, V](stores: Seq[Store[Self, K, V]]): Store[Self, K, V] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do this, the trait returns don't need to change:
import Store.{selectFirstSuccessfulTrial => selectFirst}
class ReplicatedStore[StoreType <: Store[StoreType, K, V], K, V](stores: Seq[StoreType])
: Store[ReplicatedStore[StoreType, K V], K, V] = {
override def get(k: K) = selectFirst(stores.map { _.get(k) })
override def multiGet(ks: Set[K]) = selectFirst(stores.map { _.multiGet(ks) })
override def update(k: K)(fn: Option[V] => Option[V]) =
Future.collect(stores.map { _.update(k)(fn) }).map { new ReplicatedStore(_) }
override def -(k: K) =
Future.collect(stores.map { _ - k }).map { new ReplicatedStore(_) }
override def +(pair: (K,V)) =
Future.collect(stores.map { _ + pair }).map { new ReplicatedStore(_) }
}
add logic for replicating writes and reads to stores
No description provided.