Skip to content

Instantly share code, notes, and snippets.

@timonv
Created February 22, 2015 16:11
Show Gist options
  • Save timonv/eee9bcbf72d17d5bf26b to your computer and use it in GitHub Desktop.
Save timonv/eee9bcbf72d17d5bf26b to your computer and use it in GitHub Desktop.
fn request_temp_code() -> TempCode {
Command::new("xdg-open").arg(format!("https://slack.com/oauth/authorize?client_id={}", SLACK_CLIENT_ID)).output().unwrap();
let server = Server::http(Ipv4Addr(127, 0, 0, 1), 9999);
let (tx, rx) = channel();
let mtx = Mutex::new(tx);
let mut guard = server.listen(move |req: Request, res: Response| {
match req.uri {
AbsolutePath(path) => {
// Trying to manually drop to see if this is the problem
let tempcode = extract_temp_code(&path).unwrap();
let gmtx = mtx.lock().unwrap();
gmtx.send(tempcode).unwrap();
drop(gmtx);
},
_ => ()
}
let mut res = res.start().unwrap();
res.write_all(b"Thanks! Please return to Lax").unwrap();
res.end().unwrap();
}).unwrap();
let tempcode = rx.recv().unwrap();
guard.close();
println!("{}", "Auth code received!");
println!("{}", "Server closed!");
// Hangs here
tempcode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment