Way too Easy

Cogo is a high-performance library for programming stackful coroutines with which you can easily develop and maintain massive concurrent programs. It can be thought as the Rust version of the popular [Goroutine][go].
Initial code frok from May and we add Many improvements(Inspired by Golang, parking_lot and crossbeam) and more...

Cogo Powerful standard library *
cogo/std/http/serverAn HTTP server is available(Body parsing upcoming) *cogo/std/http/clientAn HTTP Client(TODO) upcoming *cogo/std/queueBasic queue data structures *cogo/std/syncIncludesMutex/RwLock/WaitGroup/Semphore/chan!()/chan!(1000)...and more.. *cogo/std/deferDefers evaluation of a block of code until the end of the scope. *cogo/std/mapProvides the same concurrency map as Golang, withSyncHashMapandSyncBtreeMap.It is suitable for concurrent environments with too many reads and too few writes *cogo/std/timeImprove the implementation of a high performance time *cogo/std/lazyThread/coroutine safe global variable,Lazy struct,OnceCell
Crates based on cogo implementation * cdbc Database Drivers include mysql, Postgres, AND SQLite * fast_log High-performance log impl * cogo-redis TODO: an redis client. * cogo-grpc TODO: an grpc server/client.
x8664 GNU/Linux, x8664 Windows, x86_64 Mac, aarch64 Linux OS are supported.
Support High performance channel(2 times better performance, Support the buffer);
A naive echo server implemented with Cogo: ```rust
extern crate cogo;
use cogo::net::TcpListener; use std::io::{Read, Write};
fn main() { let listener = TcpListener::bind("127.0.0.1:8000").unwrap(); while let Ok((mut stream, )) = listener.accept() { go!(move || { let mut buf = vec![0; 1024 * 16]; // alloc in heap! while let Ok(n) = stream.read(&mut buf) { if n == 0 { break; } stream.writeall(&buf[0..n]).unwrap(); } }); } }
```
There is a detailed [document][caveat] that describes Cogo's main restrictions. In general, there are four things you should follow when writing programs that use coroutines: * Don't call thread-blocking API (It will hurt the performance); * Carefully use Thread Local Storage (access TLS in coroutine might trigger undefined behavior).
It's considered unsafe with the following pattern:
rust set_tls(); // Or another coroutine API that would cause scheduling: coroutine::yield_now(); use_tls();but it's safe if your code is not sensitive about the previous state of TLS. Or there is no coroutines scheduling between set TLS and use TLS.
Note:
The first three rules are common when using cooperative asynchronous libraries in Rust. Even using a futures-based system also have these limitations. So what you should really focus on is a coroutine stack size, make sure it's big enough for your applications.
rust
cogo::config().set_stack_size(8*1024);//default is 4k=4*1024,Multiple of 4kb is recommended