Created
July 22, 2019 12:44
-
-
Save deadcheat/8eb361db0137dc4d2646664dc0158027 to your computer and use it in GitHub Desktop.
rust で CLI Parser とスレッドがうまく行かなかったやつ解決した。すごい
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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