{"id":13671960,"url":"https://github.com/co-rs/mco","last_synced_at":"2025-12-12T15:27:55.288Z","repository":{"id":57608028,"uuid":"441475645","full_name":"co-rs/mco","owner":"co-rs","description":"Rust  Async Coroutine Runtime that combines speed and ease to use","archived":false,"fork":false,"pushed_at":"2023-12-28T12:18:14.000Z","size":1273,"stargazers_count":63,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-30T14:07:22.341Z","etag":null,"topics":["async","async-runtime","asynchronous","asyncio","goroutine","mco","networking","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/co-rs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-12-24T13:41:28.000Z","updated_at":"2025-04-30T03:27:55.000Z","dependencies_parsed_at":"2023-12-22T12:20:48.369Z","dependency_job_id":"8b929faf-d99d-41ea-817d-79930cd65f6a","html_url":"https://github.com/co-rs/mco","commit_stats":{"total_commits":567,"total_committers":1,"mean_commits":567.0,"dds":0.0,"last_synced_commit":"70e16059c269e4da995fab77812640de21799fa6"},"previous_names":["co-rs/cogo"],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/co-rs/mco","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co-rs%2Fmco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co-rs%2Fmco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co-rs%2Fmco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co-rs%2Fmco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/co-rs","download_url":"https://codeload.github.com/co-rs/mco/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co-rs%2Fmco/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264862385,"owners_count":23674957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-runtime","asynchronous","asyncio","goroutine","mco","networking","rust"],"created_at":"2024-08-02T09:01:22.964Z","updated_at":"2025-12-12T15:27:55.220Z","avatar_url":"https://github.com/co-rs.png","language":"Rust","readme":"# mco\n\n\u003cimg style=\"width: 100px;height: 100px;\" width=\"100\" height=\"100\" src=\"docs/imgs/logo.png\" /\u003e\n\nmco is a high-performance library for programming stackful coroutines with which you can easily develop and maintain\nmassive concurrent programs. It can be thought as the Rust version of the popular [Goroutine][go].\n\n- [x] Most commonly used APIs\n- [ ] The current version support stack expansion\n\n\n# way mco?\n* Elegant coding,No need for async await\n* Simple concurrency(CSP model), learning Golang\n* Default MAX 6MB Stack Size\n* many std like API\n\n\u003e Initial code frok from [May](https://github.com/Xudong-Huang/may) and we add Many improvements(Inspired by [Golang](https://golang.google.cn/),  [parking_lot](https://github.com/Amanieu/parking_lot)  and [crossbeam](https://github.com/crossbeam-rs/crossbeam)) and more...\n\n\n# mco crates\n\n\u003e mco Powerful standard library\n\n* ``` mco/std/queue ``` Basic queue data structures\n* ``` mco/std/sync ```  Includes ``` Mutex/RwLock/WaitGroup/Semphore/chan!()/chan!(1000) ```...and more..\n* ``` mco/std/defer ``` Defers evaluation of a block of code until the end of the scope.\n* ``` mco/std/map ```  Provides the same concurrency map as Golang, with ```SyncHashMap``` and ```SyncBtreeMap```.It is\n  suitable for concurrent environments with too many reads and too few writes\n* ``` mco/std/vec ```  Provides the same concurrency vec\n* ``` mco/std/time ``` Improve the implementation of a high performance time\n* ``` mco/std/lazy ``` Thread/coroutine safe global variable,Lazy struct,OnceCell\n\n\u003e Crates based on mco implementation\n\n* [mco-http](https://github.com/co-rs/mco-http) High-performance coroutine HTTP server and client\n* [cdbc](https://github.com/co-rs/cdbc) Database Drivers include mysql, Postgres, AND SQLite\n* [fast_log](https://github.com/co-rs/fast_log) High-performance log impl\n* [mco-redis](https://github.com/co-rs/mco-redis) Redis client for mco\n* [mco-redis-rs](https://github.com/co-rs/mco-redis-rs) fork from ```redis-rs``` Replace only TcpStream with MCO ::TcpStream\n* [mco-rpc](https://github.com/co-rs/mco-rpc)  rpc server/client. support bincode/json rpc\n\n## Features\n\n* The stackful coroutine implementation is based on [generator][generator];\n* Support schedule on a configurable number of threads for multi-core systems;\n* Support coroutine version of a local storage ([CLS][cls]);\n* Support efficient asynchronous network I/O;\n* Support efficient timer management;\n* Support standard synchronization primitives, a semaphore, an MPMC channel, etc;\n* Support cancellation of coroutines;\n* Support graceful panic handling that will not affect other coroutines;\n* Support scoped coroutine creation;\n* Support general selection for all the coroutine API;\n* All the coroutine API are compatible with the standard library semantics;\n* All the coroutine API can be safely called in multi-threaded context;\n* Both stable, beta, and nightly channels are supported;\n* x86_64 GNU/Linux, x86_64 Windows, x86_64 Mac, aarch64 Linux OS are supported.\n\n* Support High performance chan(like golang)\n* Support WaitGroup Support(like golang)\n* Support defer!() (like golang)\n* Support Rustls\n* Support Time (like golang)\n* Support error/err!() (like golang)\n* Support select match Ok(v)/Err(e)  (like golang)\n* Support Lazy/OnceCell\n* Support SyncMap(like golang)\n* Support Ticker(like golang)\n\n## Usage\n```toml\nmco = \"0.1\"\n```\nA naive echo server implemented with mco:\n\n```rust\n#[macro_use]\nextern crate mco;\n\nuse mco::net::TcpListener;\nuse std::io::{Read, Write};\n\nfn main() {\n    let listener = TcpListener::bind(\"127.0.0.1:8000\").unwrap();\n    while let Ok((mut stream, _)) = listener.accept() {\n        go!(move || {\n            let mut buf = vec![0; 1024 * 16]; // alloc in heap!\n            while let Ok(n) = stream.read(\u0026mut buf) {\n                if n == 0 {\n                    break;\n                }\n                stream.write_all(\u0026buf[0..n]).unwrap();\n            }\n        });\n    }\n}\n\n```\n\n## More examples\n\n### The I/O heavy bound examples\n\n* [An echo server](examples/src/echo.rs)\n* [An echo client](examples/src/echo_client.rs)\n* [simple HTTP](examples/src/http.rs)\n* [simple HTTPS](examples/src/https.rs)\n* [tiny  HTTP](https://github.com/co-rs/mco-http)\n* [WebSockets](examples/src/websocket.rs)\n\n## Caveat\n\nThere is a detailed [document][caveat] that describes mco's main restrictions. In general, there are four things you\nshould follow when writing programs that use coroutines:\n\n* Don't call thread-blocking API (It will hurt the performance);\n* Carefully use Thread Local Storage (access TLS in coroutine might trigger undefined behavior).\n\n\u003e It's considered **unsafe** with the following pattern:\n\u003e ```rust\n\u003e set_tls();\n\u003e // Or another coroutine API that would cause scheduling:\n\u003e yield_now(); \n\u003e use_tls();\n\u003e ```\n\u003e 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.\n\n* Don't run CPU bound tasks for long time, but it's ok if you don't care about fairness;\n* Don't run thread::sleep() on mco coroutine\n* In most modern operating systems, when starting a process, the standard Thread stack size is usually 8 MB, and mco provides a maximum stack space of 6MB. Typically, operating systems load memory pages on demand, such as starting about 1 million processes on my Mac/Unix system, which requires 15GB of memory space. \n* Don't exceed the coroutine stack. There is a guard page for each coroutine stack. When stack overflow occurs, it will\n  trigger segment fault error.\n\n**Note:**\n\u003e 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.\n\n## How to tune a stack size\n\n```rust\nmco::config().set_stack_size(6*1024*1024);\n```\n\n* We are in urgent need of financial support and cooperation, welcome to contact us\n* email: zhuxiujia@qq.com\n* wechat: zxj347284221\n\u003e 捐赠\n\n\u003cimg style=\"width: 400px;height: 600px;\" width=\"400\" height=\"600\" src=\"https://raw.githubusercontent.com/rbatis/rbatis.io/master/docs/_media/wx_account.png\" alt=\"zxj347284221\" /\u003e\n\n\u003e 联系方式(添加好友请备注'mco') 微信群：先加微信，然后拉进群\n\n\u003cimg style=\"width: 400px;height: 500px;\" width=\"400\" height=\"500\" src=\"https://raw.githubusercontent.com/rbatis/rbatis.io/master/docs/_media/wechat.jpg\" alt=\"zxj347284221\" /\u003e\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco-rs%2Fmco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fco-rs%2Fmco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco-rs%2Fmco/lists"}