{"id":24974386,"url":"https://github.com/sjinks/coro-cpp","last_synced_at":"2025-09-05T02:37:21.103Z","repository":{"id":275582398,"uuid":"926524706","full_name":"sjinks/coro-cpp","owner":"sjinks","description":"Yet Another C++20 Coroutine Library","archived":false,"fork":false,"pushed_at":"2025-06-11T18:03:00.000Z","size":147,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-11T19:52:32.898Z","etag":null,"topics":["async-await","asynchronous-programming","coroutines","cpp","cpp20","cpp20-coroutine"],"latest_commit_sha":null,"homepage":"https://sjinks.github.io/coro-cpp/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sjinks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"custom":["https://www.paypal.com/donate/?hosted_button_id=SAG6877JDJ3KU","https://send.monobank.ua/jar/7rosVfiwKM"]}},"created_at":"2025-02-03T12:12:04.000Z","updated_at":"2025-06-03T17:27:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"8c16d813-15aa-4d59-8d41-67766795f529","html_url":"https://github.com/sjinks/coro-cpp","commit_stats":null,"previous_names":["sjinks/coro-cpp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sjinks/coro-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fcoro-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fcoro-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fcoro-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fcoro-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sjinks","download_url":"https://codeload.github.com/sjinks/coro-cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fcoro-cpp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262132662,"owners_count":23264041,"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-await","asynchronous-programming","coroutines","cpp","cpp20","cpp20-coroutine"],"created_at":"2025-02-03T20:03:54.843Z","updated_at":"2025-06-26T19:33:15.650Z","avatar_url":"https://github.com/sjinks.png","language":"C++","funding_links":["https://www.paypal.com/donate/?hosted_button_id=SAG6877JDJ3KU","https://send.monobank.ua/jar/7rosVfiwKM"],"categories":[],"sub_categories":[],"readme":"# WWA Coro — Yet Another C++20 Coroutine Library\n\n[![Build and Test](https://github.com/sjinks/coro-cpp/actions/workflows/ci.yml/badge.svg)](https://github.com/sjinks/coro-cpp/actions/workflows/ci.yml)\n[![CodeQL](https://github.com/sjinks/coro-cpp/actions/workflows/codeql.yml/badge.svg)](https://github.com/sjinks/coro-cpp/actions/workflows/codeql.yml)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sjinks_coro-cpp\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=sjinks_coro-cpp)\n\nThis project provides a set of coroutine-based asynchronous utilities and generators for C++20. It includes synchronous and asynchronous generators, tasks, and various utilities to facilitate coroutine-based programming.\n\n## Features\n\n- **Synchronous Generators**: Create coroutine-based generators that produce values synchronously.\n- **Asynchronous Generators**: Create coroutine-based generators that produce values asynchronously.\n- **Tasks**: Manage coroutine-based tasks that produce values of a specified type.\n\n## Getting Started\n\n### Prerequisites\n\n- C++20 compatible compiler\n- CMake 3.23 or higher\n\n### Installation\n\n```sh\ncmake -B build\ncmake --build build\nsudo cmake --install build\n```\n\n#### Configuration Options\n\n| Option                  | Description                                                               | Default |\n|-------------------------|---------------------------------------------------------------------------|---------|\n| `BUILD_TESTS`           | Build tests                                                               | `ON`    |\n| `BUILD_EXAMPLES`        | Build examples                                                            | `ON`    |\n| `BUILD_DOCS`            | Build documentation                                                       | `ON`    |\n| `BUILD_INTERNAL_DOCS`   | Build internal documentation                                              | `OFF`   |\n| `ENABLE_MAINTAINER_MODE`| Maintainer mode (enable more compiler warnings, treat warnings as errors) | `OFF`   |\n| `USE_CLANG_TIDY`        | Use `clang-tidy` during build                                             | `OFF`   |\n\nThe `BUILD_DOCS` (public API documentation) and `BUILD_INTERNAL_DOCS` (public and private API documentation) require [Doxygen](https://www.doxygen.nl/)\nand, optionally, `dot` (a part of [Graphviz](https://graphviz.org/)).\n\nThe `USE_CLANG_TIDY` option requires [`clang-tidy`](https://clang.llvm.org/extra/clang-tidy/).\n\n#### Build Types\n\n| Build Type       | Description                                                                     |\n|------------------|---------------------------------------------------------------------------------|\n| `Debug`          | Build with debugging information and no optimization.                           |\n| `Release`        | Build with optimization for maximum performance and no debugging information.   |\n| `RelWithDebInfo` | Build with optimization and include debugging information.                      |\n| `MinSizeRel`     | Build with optimization for minimum size.                                       |\n| `ASAN`           | Build with AddressSanitizer enabled for detecting memory errors.                |\n| `LSAN`           | Build with LeakSanitizer enabled for detecting memory leaks.                    |\n| `UBSAN`          | Build with UndefinedBehaviorSanitizer enabled for detecting undefined behavior. |\n| `TSAN`           | Build with ThreadSanitizer enabled for detecting data races.                    |\n| `Coverage`       | Build with code coverage analysis enabled.                                      |\n\nASAN, LSAN, UBSAN, TSAN, and Coverage builds are only supported with GCC or clang.\n\nCoverage build requires `gcov` (GCC) or `llvm-gcov` (clang) and [`gcovr`](https://gcovr.com/en/stable/).\n\n### Running Tests\n\nTo run the tests, use the following command:\n\n```sh\nctest -T test --test-dir build/test\n```\n\nor run the following binary:\n\n```sh\n./build/test/coro_test\n```\n\nThe test binary uses [Google Test](http://google.github.io/googletest/) library.\nIts behavior [can be controlled](http://google.github.io/googletest/advanced.html#running-test-programs-advanced-options)\nvia environment variables and/or command line flags.\n\nRun `coro_test --help` for the list of available options.\n\n## Usage Examples\n\nThe documentation is available at [https://sjinks.github.io/coro-cpp/](https://sjinks.github.io/coro-cpp/).\n\n### Eager Coroutine (`eager_task`)\n\nAn *eager coroutine* (or *hot-start coroutine*) starts execution immediately upon creation and keeps running until the first suspending `co_await`.\n\n```cpp\n#include \u003cwwa/coro/eager_task.h\u003e\n\nwwa::coro::eager_task my_task()\n{\n    co_await some_other_coroutine();\n}\n```\n\nSee [examples/eager_task.cpp](https://github.com/sjinks/coro-cpp/blob/master/examples/eager_task.cpp)\n\nEager coroutines can `co_await` other coroutines but they cannot be `co_await`'ed.\n\n### Task (`task\u003cT\u003e`)\n\n*Tasks* are lightweight coroutines that start executing when they are awaited; they can optionally return values (the type of the return value\nis determined by the template parameter `T`). Use tasks to create your coroutines, and use `co_await` or `co_yield` within tasks\nto perform asynchronous operations.\n\n```cpp\n#include \u003cwwa/coro/task.h\u003e\n\nwwa::coro::task\u003cint\u003e task1()\n{\n    co_return 123;\n}\n\nwwa::coro::task\u003cint\u003e task2()\n{\n    co_return 456;\n}\n\nwwa::coro::task\u003cint\u003e sum()\n{\n    const auto a = co_await task1();\n    const auto b = co_await task2();\n    co_return a + b;\n}\n\nwwa::coro::task\u003c\u003e print()\n{\n    std::cout \u003c\u003c \"The result is \" \u003c\u003c co_await sum() \u003c\u003c \"\\n\";\n}\n```\n\nIt is possible to turn any task (or any awaitable) into a fire-and-forget eager coroutine. For the example above,\n\n```cpp\n#include \u003cwwa/coro/eager_task.h\u003e\n#include \u003cwwa/coro/task.h\u003e\n\nwwa::coro::run_awaitable(print);\n```\n\nSee [examples/task.cpp](https://github.com/sjinks/coro-cpp/blob/master/examples/task.cpp).\n\n### Generators (`generator\u003cT\u003e`)\n\n*Generators* are special coroutines that produce sequences of values of a specified type (`T`). These values are produced lazily and *synchronously*.\n\nThe coroutine body is able to yield values of type `T` using the `co_yield` keyword.\nHowever, the coroutine body is not able to use the `co_await` keyword; values **must** be produced synchronously.\n\nGenerators can be used with range-based `for` loops and ranges.\n\n```cpp\n#include \u003cwwa/coro/generator.h\u003e\n\nwwa::coro::generator\u003cint\u003e fibonacci(int n)\n{\n    int a = 0;\n    int b = 1;\n\n    if (n \u003e 0) {\n        co_yield a;\n    }\n\n    if (n \u003e 1) {\n        co_yield b;\n    }\n\n    for (int i = 2; i \u003c n; ++i) {\n        auto s = a + b;\n        co_yield s;\n        a = b;\n        b = s;\n    }\n}\n\n// ...\n\nstd::cout \u003c\u003c \"The first 10 Fibonacci numbers are: \";\nfor (auto n : fibonacci(10)) {\n    std::cout \u003c\u003c n \u003c\u003c ' ';\n}\n```\n\nSee [examples/generator.cpp](https://github.com/sjinks/coro-cpp/blob/master/examples/generator.cpp).\n\n### Asynchronous Generators (`async_generator\u003cT\u003e`)\n\n*Generators* are special coroutines that produce sequences of values of a specified type (`T`). These values are produced lazily and *asynchronously*.\n\nUnlike the synchronous counterpart, the coroutine body is able to use both `co_await` and `co_yield` expressions.\n\n```cpp\n// Simulates an asynchronous task\nwwa::coro::task\u003cint\u003e get_next_value(int n)\n{\n    co_return n + 1;\n}\n\nwwa::coro::async_generator\u003cint\u003e async_first_n(int n)\n{\n    int v = 0;\n    while (v \u003c n) {\n        co_yield v;\n        v = co_await get_next_value(v);\n    }\n}\n\n// ...\n\nauto gen = async_first_n(5);\nauto it  = co_await gen.begin();  // IMPORTANT! co_await is required\nauto end = gen.end();\n\nwhile (it != end) {\n    std::cout \u003c\u003c *it \u003c\u003c \"\\n\";\n    co_await ++it;                // IMPORTANT! co_await is required\n}\n```\n\nSee [examples/async_generator.cpp](https://github.com/sjinks/coro-cpp/blob/master/examples/async_generator.cpp).\n\nUnfortunately, it is impossible to use asynchronous iterators directly in range-based `for` loops.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjinks%2Fcoro-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsjinks%2Fcoro-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjinks%2Fcoro-cpp/lists"}