#do #coroutines #use #library #expected

archived nightly monkeys

Coroutines with async/await/yield

1 unstable release

Uses old Rust 2015

0.1.0 Mar 23, 2016

MIT license

20KB
533 lines

Monkeys are new coroutines

This is pre-alpha library, nothing works as expected yet.

Goals

Coroutines with async/await/yield for Rust.

fn main() {

   async(|flow| {

     let stream = async(|flow| {
        for i in 0..5 {
            flow.yield_it(i);
        }
      });

      for r in stream {
        println!("got streamed: {:?}", r);
      }


      let awaitable = async(|flow | {
        1 + 1
      });

      let r = flow.await(awaitable);

      println!("awaitable res: {:?}", r);


   }).get();
}

prints

> got streamed: 0
> got streamed: 1
> got streamed: 2
> got streamed: 3
> got streamed: 4
> awaitable res: 2

Non goals

There won't be network stack itself. Monkeys are building blocks for higher level libraries.

Plan

  • Initial prototype
  • Simple timers
  • Support for pluggable network stack
  • Benchmarking and optimizations

Dependencies

~2MB
~50K SLoC