mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
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:
parent
1752853929
commit
aead487e94
42
lib/asyncpacks/src/asynchistorystore.rs
Normal file
42
lib/asyncpacks/src/asynchistorystore.rs
Normal 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))
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user