使用旧的Rust 2015
| 0.0.1 |  | 
|---|
#59 in #spawn
89KB
 1.5K  SLoC
coroutine-rs 
Rust中的协程库
[dependencies.coroutine-rs]
git = "https://github.com/rustcc/coroutine-rs.git"
用法
协程的基本用法
extern crate coroutine;
use coroutine::coroutine::{spawn, sched};
fn main() {
    // Spawn a new coroutine
    let coro = spawn(move|| {
        println!("Hello in coroutine!");
        // Yield back to it's parent
        sched();
        println!("We are back!!");
        // Spawn a new coroutine
        spawn(move|| {
            println!("Hello inside");
        }).join().unwrap();
        println!("Good bye");
    });
    coro.resume().unwrap();
    println!("We are here!");
    // Resume the coroutine
    coro.resume().unwrap();
    println!("Back to main.");
}
目标
- 
基本单线程协程支持 
- 
可克隆的协程句柄 
- 
线程安全:一次只能在单个线程中恢复协程 
- 
具有工作窃取功能的线程调度器 
- 
异步I/O支持 
依赖项
~405–660KB