Skip to content

Instantly share code, notes, and snippets.

@deadcheat
Created July 22, 2019 12:44
Show Gist options
  • Save deadcheat/8eb361db0137dc4d2646664dc0158027 to your computer and use it in GitHub Desktop.
Save deadcheat/8eb361db0137dc4d2646664dc0158027 to your computer and use it in GitHub Desktop.
rust で CLI Parser とスレッドがうまく行かなかったやつ解決した。すごい
extern crate reqwest;
use structopt::StructOpt;
use std::thread;
use std::sync::mpsc;
use std::sync::Arc;
#[derive(StructOpt, Debug, Clone)]
#[structopt()]
struct Opt {
// PATH
#[structopt(name = "PATH")]
path: String,
}
fn main() {
let _opt = Opt::from_args();
let opt = Arc::new(_opt.clone());
println!("{:#?}", opt);
let client = Arc::new(reqwest::Client::new());
let mut children = Vec::new();
// let url: Arc<&str> = Arc::new(&opt.path);
for _ in 0..2 {
let client = Arc::clone(&client);
let opt = Arc::clone(&opt);
let child = thread::spawn(move || {
let url = &opt.path;
client.get(url).send();
});
children.push(child);
}
for c in children {
c.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment