How to stop hyper's server


#1

Hi!
I try to implement google oauth2 client for practice. I need to start http server to process only one request and stop server after this. I’ve got this code with some help:

    let addr: SocketAddr = ([127, 0, 0, 1], 3000).into();
    let (sender, receiver) = futures::sync::oneshot::channel::<()>();
    let sender = RefCell::new(Some(sender));
    let proc = move || {
        let res = service_fn_ok(got_google_response);
        sender.borrow_mut().take().unwrap().send(());
        res
    };

    let server = Server::bind(&addr)
        .serve(proc)
        .with_graceful_shutdown(receiver)
        .map_err(|e| eprintln!("server error: {}", e));

The string sender.borrow_mut().take().unwrap().send(()); looks too complex for simple purpose - just send message to receiver. But I can’t find more simple way. If I use sender without wrappers closure proc type become FnOnce but serve method need Fn.

How can I solve this collision? And is another way to stop server exist?

Thank you.