{"id":13438394,"url":"https://github.com/rustasync/runtime","last_synced_at":"2025-03-19T18:32:56.521Z","repository":{"id":57664258,"uuid":"181468963","full_name":"rustasync/runtime","owner":"rustasync","description":"Empowering everyone to build asynchronous software","archived":true,"fork":false,"pushed_at":"2019-10-29T19:46:54.000Z","size":8553,"stargazers_count":862,"open_issues_count":0,"forks_count":28,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-05-03T02:28:03.118Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.rs/runtime","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/rustasync.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-15T11:00:38.000Z","updated_at":"2024-03-21T14:17:03.000Z","dependencies_parsed_at":"2022-09-10T14:11:54.717Z","dependency_job_id":null,"html_url":"https://github.com/rustasync/runtime","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustasync%2Fruntime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustasync%2Fruntime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustasync%2Fruntime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustasync%2Fruntime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rustasync","download_url":"https://codeload.github.com/rustasync/runtime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244483731,"owners_count":20460168,"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":[],"created_at":"2024-07-31T03:01:05.139Z","updated_at":"2025-03-19T18:32:56.118Z","avatar_url":"https://github.com/rustasync.png","language":"Rust","funding_links":[],"categories":["Libraries","Rust","库","库 Libraries","异步（Asynchronous）"],"sub_categories":["Asynchronous","异步","异步 Asynchronous","天文（Astronomy）"],"readme":"\u003ch1 align=\"center\"\u003eRuntime\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n \u003cstrong\u003e\n   Empowering everyone to build asynchronous software.\n \u003c/strong\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003c!-- Crates version --\u003e\n  \u003ca href=\"https://crates.io/crates/runtime\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/v/runtime.svg?style=flat-square\"\n    alt=\"Crates.io version\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Build Status --\u003e\n  \u003ca href=\"https://dev.azure.com/yoshuawuyts/rustasync/_build?definitionId=2\"\u003e\n    \u003cimg src=\"https://img.shields.io/azure-devops/build/yoshuawuyts/rustasync/2/master.svg?style=flat-square\"\n      alt=\"Build Status\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Downloads --\u003e\n  \u003ca href=\"https://crates.io/crates/runtime\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/d/runtime.svg?style=flat-square\"\n      alt=\"Download\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- docs.rs docs --\u003e\n  \u003ca href=\"https://docs.rs/runtime\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square\"\n      alt=\"docs.rs docs\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003e\n    \u003ca href=\"https://docs.rs/runtime\"\u003e\n      API Docs\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/rustasync/runtime/blob/master/.github/CONTRIBUTING.md\"\u003e\n      Contributing\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://discord.gg/NtbaeUm\"\u003e\n      Chat\n    \u003c/a\u003e\n  \u003c/h3\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003csub\u003eBuilt with ⛵ by \u003ca href=\"https://github.com/rustasync\"\u003eThe Rust Async Ecosystem WG\u003c/a\u003e\n\u003c/div\u003e\n\n## ⚠️ Deprecation notice  ⚠️\nRuntime is no longer actively developed. The team behind Runtime has moved on to\nbuilding [async-std](https://async.rs/): an asynchronous version of the Rust\nstdlib.\n\nIf you're looking for an asynchronous runtime please consider using\n[async-std](https://docs.rs/async-std) or [tokio](https://docs.rs/tokio).\n\n## About\nRuntime is what we imagine async APIs could look like if they were part of stdlib. We want async\nRust to be an experience that mirrors the quality of the standard lib. We believe that in order for\nRust to succeed it's not only important to make async Rust _possible_, it's crucial to make async\nRust feel _seamless_.\n\nAnd the embodiment of these values is Runtime: a library crafted to empower everyone to build\nasynchronous software.\n\n- __runtime agnostic:__ Runtime comes with minimal OS bindings out of the box, but switching to a\n    different runtime is a matter of changing a single line.\n- __await anywhere:__ Runtime allows you to write async main functions, async tests, and async\n    benchmarks. Experience what first-class async support in Rust feels like.\n- __built for performance:__ Runtime is the thinnest layer possible on top of the backing\n    implementations. All of the speed, none of the boilerplate.\n\n## Examples\n__UDP Echo Server__\n```rust\nuse runtime::net::UdpSocket;\n\n#[runtime::main]\nasync fn main() -\u003e std::io::Result\u003c()\u003e {\n    let mut socket = UdpSocket::bind(\"127.0.0.1:8080\")?;\n    let mut buf = vec![0u8; 1024];\n\n    println!(\"Listening on {}\", socket.local_addr()?);\n\n    loop {\n        let (recv, peer) = socket.recv_from(\u0026mut buf).await?;\n        let sent = socket.send_to(\u0026buf[..recv], \u0026peer).await?;\n        println!(\"Sent {} out of {} bytes to {}\", sent, recv, peer);\n    }\n}\n```\n\nTo send messages do:\n```sh\n$ nc -u localhost 8080\n```\n\n__More Examples__\n- [Hello World](https://github.com/rustasync/runtime/tree/master/examples/hello.rs)\n- [Guessing Game](https://github.com/rustasync/runtime/blob/master/examples/guessing.rs)\n- [TCP Echo Server](https://github.com/rustasync/runtime/blob/master/examples/tcp-echo.rs)\n- [TCP Client](https://github.com/rustasync/runtime/tree/master/examples/tcp-client.rs)\n- [TCP Proxy Server](https://github.com/rustasync/runtime/tree/master/examples/tcp-proxy.rs)\n- [UDP Echo Server](https://github.com/rustasync/runtime/tree/master/examples/udp-echo.rs)\n- [UDP Client](https://github.com/rustasync/runtime/tree/master/examples/udp-client.rs)\n\n## Attributes\nRuntime introduces 3 attributes to enable the use of await anywhere, and swap between different\nruntimes. Each Runtime is bound locally to the initializing thread. This enables the testing of\ndifferent runtimes during testing or benchmarking.\n\n```rust\n#[runtime::main]\nasync fn main() {}\n\n#[runtime::test]\nasync fn my_test() {}\n\n#[runtime::bench]\nasync fn my_bench() {}\n```\n\n## Runtimes\nSwitching runtimes is a one-line change:\n\n```rust\n/// Use the default Native Runtime\n#[runtime::main]\nasync fn main() {}\n\n/// Use the Tokio Runtime\n#[runtime::main(runtime_tokio::Tokio)]\nasync fn main() {}\n```\n\nThe following backing runtimes are available:\n\n- [Runtime Native (default)](https://crates.io/crates/runtime-native) provides\n  a thread pool, bindings to the OS, and a concurrent scheduler.\n- [Runtime Tokio](https://crates.io/crates/runtime-tokio) provides a thread pool, bindings to the OS, and\n  a work-stealing scheduler.\n\n## Performance\nRuntime provides performance that's competitive with most other systems languages, and great\nergonomics to match.\n\nBecause we don't know what your workload is like, we can't predict which runtime will be able to\nmaximize resource consumption for your use case.\n\nBut we can tell from our benchmarks that the difference between using Runtime and not using Runtime\ndoesn't show up for IO-bound applications.\n```txt\n name          baseline:: ns/iter  native:: ns/iter  diff ns/iter    diff %  speedup\n notify_self   1,350,882           1,237,416             -113,466    -8.40%   x 1.09\n poll_reactor  2,270,428           2,162,264             -108,164    -4.76%   x 1.05\n```\n\n## Installation\nWith [cargo-edit](https://crates.io/crates/cargo-edit) do:\n```sh\n$ cargo add runtime --allow-prerelease\n```\n\nTo use Futures in the same project, make sure to install\n[futures-preview](https://docs.rs/futures-preview/) for std futures.\n```sh\n$ cargo add futures-preview --allow-prerelease\n```\n\n`futures-preview` provides support for std futures/futures 0.3, while `futures` provides support for\nthe no longer developed futures 0.1. Once futures land in stdlib, it's expected that the two crates\nwill merge back into `futures`. With the hopes that eventually most of `futures` will be part of\nstdlib.\n\n## FAQ\n### When is it useful to switch Runtimes?\nWhat might be the best solution now, might not stay the best in the future. As Rust grows, so will\nthe ecosystem. By making runtimes pluggable, your code can be forward compatible with any future\nchanges. And as things evolve, you'll be able to test out the benefit new developments in the\necosystem have on your code by just changing a single line.\n\n### How is Runtime versioned?\nWe're currently in the `0.3-alpha` range of releases, mirroring the Futures libraries. Once\nFutures hits 1.0, we'll follow suit and move over to semver proper.\n\nThis doesn't mean that Runtime won't release breaking changes. But if we do, we'll release a new\nmajor version, and provide instructions on how to upgrade. We view Runtime to be a foundational\npiece of technology, and that means we have to be serious about our stability guarantees.\n\n### Can I use Runtime in production?\nRuntime is a thin layer that sits between your code and the backing runtimes. If you trust the\nbacking runtime in production, then you can probably trust Runtime too.\n\n### Why is Runtime Native the default?\nWe believe Runtime Native provides a balanced implementation that works well for most scenarios. The\ncodebase is small and comprehensive, and the algorithms simple yet performant.\n\nSpecific runtimes might introduce different trade-offs, and with Runtime you're able to compare, and\npick the best fit for your requirements.\n\n### Can Runtime be used on embedded devices?\nRuntime is designed to be compatible with micro processors, but not with micro controllers. Out of\nthe box Runtime works on embedded devices such as Raspberry Pis, and with the appropriate backends\nit should also work on phones.\n\nMicro controllers are very specific in what they provide, and while a Runtime-like library might be\npossible in the future, it's still early for the ecosystem and APIs would likely also need to be\ndifferent. We don't know what the future holds, but for now we've chosen not to target micro\ncontrollers.\n\n### When will Timers and File System support land?\nTimers are next up on the list of things we want to target, together with Unix Domain Sockets.\nFilesystem is a bit further behind because currently the implementations in the backing runtimes are\nchanging, and we're not sure yet how to best abstract that.\n\nGetting things right takes time. But if you'd like to move the state of async forward, we'd love for\nyou to get involved!\n\n## Safety\nThis crate uses ``#![deny(unsafe_code)]`` to ensure everything is implemented in 100% Safe Rust.\n\n## Contributing\nWant to join us? Check out our [The \"Contributing\" section of the\nguide][contributing] and take a look at some of these issues:\n\n- [Issues labeled \"good first issue\"][good-first-issue]\n- [Issues labeled \"help wanted\"][help-wanted]\n\n#### Conduct\n\nThe Runtime project adheres to the [Contributor Covenant Code of\nConduct](https://github.com/rustasync/runtime/blob/master/.github/CODE_OF_CONDUCT.md).  This\ndescribes the minimum behavior expected from all contributors.\n\n## License\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n#### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\n[releases]: https://github.com/rustasync/runtime/releases\n[contributing]: https://github.com/rustasync/runtime/blob/master/.github/CONTRIBUTING.md\n[good-first-issue]: https://github.com/rustasync/runtime/labels/good%20first%20issue\n[help-wanted]: https://github.com/rustasync/runtime/labels/help%20wanted\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustasync%2Fruntime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustasync%2Fruntime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustasync%2Fruntime/lists"}