Skip to content

Instantly share code, notes, and snippets.

@andoriyu
Created June 20, 2017 07:55
Show Gist options
  • Save andoriyu/bcd5d0e27aa09381a37be4d6322499dd to your computer and use it in GitHub Desktop.
Save andoriyu/bcd5d0e27aa09381a37be4d6322499dd to your computer and use it in GitHub Desktop.
pub trait ClientExt<T: Service<Request=Frame,Response=Frame,Future=FrameFuture,Error=io::Error>> {
fn service(&self) -> Rc<RefCell<T>>;
fn session(&self) -> Rc<RefCell<ClientSession>>;
fn authenticate(&self) -> Box<Future<Item = (), Error = io::Error>> {
let session = self.session().clone();
let service = self.service().clone();
let hello_frame = session.borrow().make_hello();
let hello_future = service.borrow().call(hello_frame);
let ret = hello_future.and_then(|hello_resp| {
let initiate = session.borrow_mut().make_initiate(&hello_resp).unwrap();
service.borrow().call(initiate).and_then(|_| ok(()))
});
Box::new(ret)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment