目录

executor

docs.rs docs

[dependencies]
executor = "0.6"

Features

  • #![no_std] + alloc
  • global executor for easy spawning
  • simple enough to learn from! (~ 100 lines)
  • simple macros for async entry functions

Example

A web assembly example

#[no_mangle]
#[executor::entry]
pub fn main() {
    console_log("Hello");
    set_timeout(1000).await;
    console_log("World!");
}

fn set_timeout(milliseconds:u32) -> TimeoutFuture {
   // create a timeout future and store globally
}

#[no_mangle]
pub fn timeout_complete() -> () {
    // find your timeout future and wake it's waker
}

async-std

Want to use async-std?

use async_std::task::sleep;
use std::time::Duration;

#[executor::main]
async fn main() {
    println!("hello");
    sleep(Duration::from_secs(1)).await;
    println!("world!");
}

Want to replace the global executor?

Write your own with this trait

pub trait GlobalExecutor {
    fn spawn(&mut self, future: Box<dyn Future<Output = ()> + 'static + Send + Unpin>);
}
executor::set_global_executor(MY_EXECUTOR);

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in executor by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

关于

An async/await executor for Rust

132.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号