#coroutine #basic #spawn

已删除 coroutine-rs

Rust中的协程库

使用旧的Rust 2015

0.0.1 2015年4月13日

#59 in #spawn

MIT/ISC 许可证

89KB
1.5K SLoC

Rust 1.5K SLoC // 0.2% comments • Rust 包仓库 GNU Style Assembly 331 SLoC // 0.3% comments • Rust 包仓库

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