#coroutine #multi-thread

bin+lib may_waiter

Simple coroutine communication blocker

3 releases

Uses old Rust 2015

0.1.2 Apr 15, 2019
0.1.1 Jan 31, 2019
0.1.0 May 10, 2018

#4 in #multi-thread

MIT/Apache

9KB
174 lines

Build Status Current Crates.io Version Document

coroutine waiter library

This library provide a map associated blocking primitive that waiting for a response produced by another coroutine

Usage

  • the map associated interface is through WaiterMap
fn test_waiter_map() {
    let req_map = Arc::new(WaiterMap::<usize, usize>::new());
    let rmap = req_map.clone();

    let key = 1234;

    // one coroutine wait data send from another coroutine
    // prepare the waiter first
    let waiter = req_map.new_waiter(key);

    // trigger the rsp in another coroutine
    go!(move || rmap.set_rsp(&key, 100).ok());

    // this will block until the rsp was set
    let result = waiter.wait_rsp(None).unwrap();
    assert_eq!(result, 100);
}

Dependencies

~1–1.4MB
~29K SLoC