1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! RPCクライアント。
use fibers_rpc;
use futures::{Async, Future, Poll};
use trackable::error::ErrorKindExt;

use {Error, ErrorKind, Result};

pub mod config;
pub mod frugalos;
pub mod mds;

#[derive(Debug)]
struct Response<T>(fibers_rpc::client::Response<Result<T>>);
impl<T> Future for Response<T> {
    type Item = T;
    type Error = Error;

    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
        match self.0.poll() {
            Err(e) => {
                let kind = match *e.kind() {
                    fibers_rpc::ErrorKind::InvalidInput => ErrorKind::InvalidInput,
                    fibers_rpc::ErrorKind::Unavailable => ErrorKind::Unavailable,
                    fibers_rpc::ErrorKind::Timeout => ErrorKind::Timeout,
                    fibers_rpc::ErrorKind::Other => ErrorKind::Other,
                };
                Err(track!(kind.takes_over(e)).into())
            }
            Ok(Async::NotReady) => Ok(Async::NotReady),
            Ok(Async::Ready(result)) => track!(result.map(Async::Ready)),
        }
    }
}