#version #test #promiseout的rust版本

promise_out

promiseOut version for rust

2 releases (1 stable)

1.0.0 May 31, 2023
0.1.0 Mar 6, 2023

#681 in Concurrency

MIT license

16KB
288 lines

PromiseOut-rust

promiseOut的rust版本

add cargo.toml

[dependencies]
 promise_out = "0.1.0"

example

#[test]
fn test_promise_out_resolve() {
    let (op, op_a) = Producer::<String, ()>::new();
    let task1 = thread::spawn(move || {
        block_on(async {
            println!("我等到了{:?}", op_a.await);
        })
    });
    let task2 = thread::spawn(move || {
        block_on(async {
            println!("我发送了了{:?}", op.resolve(String::from("🍓")));
        })
    });
    task1.join().expect("The task1 thread has panicked");
    task2.join().expect("The task2 thread has panicked");
}

#[test]
fn test_promise_out_reject() {
    let (a, b) = Producer::<String, String>::new();
    let task1 = thread::spawn(|| {
        block_on(async {
            println!("我等到了{:?}", b.await);
        })
    });
    let task2 = thread::spawn(|| {
        block_on(async {
            println!("我发送了了{:?}", a.reject(String::from("reject!!")));
        })
    });
    task1.join().expect("The task1 thread has panicked");
    task2.join().expect("The task2 thread has panicked");
}

No runtime deps