asyncpacks: add AsyncHistoryStore

Summary:
Similarly to AsyncDataStore, this is just a blocking wrapper around a
HistoryStore.

Reviewed By: DurhamG

Differential Revision: D13891140

fbshipit-source-id: 76acadfc1849770b47e2400ce8c70f7e32bba4df
This commit is contained in:
Xavier Deguillard 2019-02-01 17:08:52 -08:00 committed by Facebook Github Bot
parent 1752853929
commit aead487e94
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,42 @@
// Copyright 2019 Facebook, Inc.
use failure::Error;
use tokio::prelude::*;
use cloned::cloned;
use revisionstore::{Ancestors, HistoryStore, Key, NodeInfo};
use crate::util::AsyncWrapper;
/// Allow a `HistoryStore` to be used in an asynchronous context
pub struct AsyncHistoryStore<T: HistoryStore> {
history: AsyncWrapper<T>,
}
impl<T: HistoryStore + Send> AsyncHistoryStore<T> {
pub(crate) fn new(store: T) -> Self {
AsyncHistoryStore {
history: AsyncWrapper::new(store),
}
}
/// Asynchronously call the HistoryStore::get_ancestors method.
pub fn get_ancestors(&self, key: &Key) -> impl Future<Item = Ancestors, Error = Error> + Send {
cloned!(key);
self.history.block(move |store| store.get_ancestors(&key))
}
/// Asynchronously call the HistoryStore::get_missing method.
pub fn get_missing(
&self,
keys: Vec<Key>,
) -> impl Future<Item = Vec<Key>, Error = Error> + Send {
self.history.block(move |store| store.get_missing(&keys))
}
/// Asynchronously call the HistoryStore::get_node_info method.
pub fn get_node_info(&self, key: &Key) -> impl Future<Item = NodeInfo, Error = Error> + Send {
cloned!(key);
self.history.block(move |store| store.get_node_info(&key))
}
}

View File

@ -5,8 +5,10 @@ mod util;
pub mod asyncdatapack;
pub mod asyncdatastore;
pub mod asynchistorystore;
pub mod asyncmutabledatapack;
pub use crate::asyncdatapack::AsyncDataPack;
pub use crate::asyncdatastore::AsyncDataStore;
pub use crate::asynchistorystore::AsyncHistoryStore;
pub use crate::asyncmutabledatapack::AsyncMutableDataPack;