Sha256: ca09bf398f69df4bac1730999e954dbbc3faf3c6512678c136e0938e7e9cd0ab

Contents?: true

Size: 1.31 KB

Versions: 23

Compression:

Stored size: 1.31 KB

Contents

use std::env;
use std::io::prelude::*;
use std::io::BufReader;
use std::process::{Command, Stdio};
use std::sync::mpsc;
use std::thread;

use jobserver::Client;

macro_rules! t {
    ($e:expr) => {
        match $e {
            Ok(e) => e,
            Err(e) => panic!("{} failed with {}", stringify!($e), e),
        }
    };
}

fn main() {
    if env::var("I_AM_THE_CLIENT").is_ok() {
        client();
    } else {
        server();
    }
}

fn server() {
    let me = t!(env::current_exe());
    let client = t!(Client::new(1));
    let mut cmd = Command::new(me);
    cmd.env("I_AM_THE_CLIENT", "1").stdout(Stdio::piped());
    client.configure(&mut cmd);
    let acq = client.acquire().unwrap();
    let mut child = t!(cmd.spawn());
    let stdout = child.stdout.take().unwrap();
    let (tx, rx) = mpsc::channel();
    let t = thread::spawn(move || {
        for line in BufReader::new(stdout).lines() {
            tx.send(t!(line)).unwrap();
        }
    });

    for _ in 0..100 {
        assert!(rx.try_recv().is_err());
    }

    drop(acq);
    assert_eq!(rx.recv().unwrap(), "hello!");
    t.join().unwrap();
    assert!(rx.recv().is_err());
    client.acquire().unwrap();
}

fn client() {
    let client = unsafe { Client::from_env().unwrap() };
    let acq = client.acquire().unwrap();
    println!("hello!");
    drop(acq);
}

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/jobserver-0.1.32/tests/client-of-myself.rs
wasmtime-28.0.0 ./ext/cargo-vendor/jobserver-0.1.32/tests/client-of-myself.rs
wasmtime-27.0.0 ./ext/cargo-vendor/jobserver-0.1.32/tests/client-of-myself.rs
wasmtime-26.0.0 ./ext/cargo-vendor/jobserver-0.1.32/tests/client-of-myself.rs
wasmtime-25.0.2 ./ext/cargo-vendor/jobserver-0.1.32/tests/client-of-myself.rs
wasmtime-25.0.1 ./ext/cargo-vendor/jobserver-0.1.32/tests/client-of-myself.rs
wasmtime-25.0.0 ./ext/cargo-vendor/jobserver-0.1.32/tests/client-of-myself.rs
wasmtime-24.0.0 ./ext/cargo-vendor/jobserver-0.1.32/tests/client-of-myself.rs
wasmtime-13.0.0 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-12.0.1 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-12.0.0 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-11.0.0 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-10.0.1 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-10.0.0 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-9.0.4 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-9.0.1 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-8.0.0 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-7.0.0 ./ext/cargo-vendor/jobserver-0.1.26/tests/client-of-myself.rs
wasmtime-6.0.1 ./ext/cargo-vendor/jobserver-0.1.25/tests/client-of-myself.rs
wasmtime-6.0.0 ./ext/cargo-vendor/jobserver-0.1.25/tests/client-of-myself.rs