{"id":13521159,"url":"https://github.com/kedixa/coke","last_synced_at":"2025-04-11T01:03:59.884Z","repository":{"id":167489034,"uuid":"643098851","full_name":"kedixa/coke","owner":"kedixa","description":"Coroutine C++ Workflow based on C++ 20","archived":false,"fork":false,"pushed_at":"2025-04-06T15:13:45.000Z","size":480,"stargazers_count":65,"open_issues_count":2,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T01:03:50.338Z","etag":null,"topics":["coroutine","cpp20"],"latest_commit_sha":null,"homepage":"","language":"C++","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/kedixa.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-05-20T05:17:03.000Z","updated_at":"2025-03-30T07:17:51.000Z","dependencies_parsed_at":"2023-10-15T14:29:26.270Z","dependency_job_id":"f4664cd4-63c8-4eba-988d-368a2a994f5c","html_url":"https://github.com/kedixa/coke","commit_stats":null,"previous_names":["kedixa/coke"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kedixa%2Fcoke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kedixa%2Fcoke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kedixa%2Fcoke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kedixa%2Fcoke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kedixa","download_url":"https://codeload.github.com/kedixa/coke/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322597,"owners_count":21084336,"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":["coroutine","cpp20"],"created_at":"2024-08-01T06:00:29.636Z","updated_at":"2025-04-11T01:03:59.858Z","avatar_url":"https://github.com/kedixa.png","language":"C++","funding_links":[],"categories":["网络"],"sub_categories":[],"readme":"# Coke\n本项目由[C++ Workflow](https://github.com/sogou/workflow)强力驱动。\n\n`Coke`是`C++ Workflow`的协程版本，在不失其高效性的前提下，`Coke`致力于实现一套简洁的协程接口，让我们多一种体验`Workflow`的方式。\n\n## 快速入门\n- 向标准输出打印`Hello World`，间隔500毫秒\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cchrono\u003e\n\n#include \"coke/wait.h\"\n#include \"coke/sleep.h\"\n\ncoke::Task\u003c\u003e helloworld(size_t n, std::chrono::milliseconds ms) {\n    for (size_t i = 0; i \u003c n; i++) {\n        if (i != 0)\n            co_await coke::sleep(ms);\n\n        std::cout \u003c\u003c \"Hello World\" \u003c\u003c std::endl;\n    }\n}\n\nint main() {\n    coke::sync_wait(helloworld(3, std::chrono::milliseconds(500)));\n\n    return 0;\n}\n```\n\n- 使用`coke::HttpClient`发起一个`GET`请求\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n\n#include \"coke/wait.h\"\n#include \"coke/http/http_client.h\"\n\ncoke::Task\u003c\u003e http_get(const std::string \u0026url) {\n    coke::HttpClient cli;\n    coke::HttpResult res = co_await cli.request(url);\n    coke::HttpResponse \u0026resp = res.resp;\n\n    if (res.state == 0) {\n        std::cout \u003c\u003c resp.get_http_version() \u003c\u003c ' '\n                  \u003c\u003c resp.get_status_code() \u003c\u003c ' '\n                  \u003c\u003c resp.get_reason_phrase() \u003c\u003c std::endl;\n    }\n    else {\n        std::cout \u003c\u003c \"ERROR: state: \" \u003c\u003c res.state\n                  \u003c\u003c \" error: \" \u003c\u003c res.error \u003c\u003c std::endl;\n    }\n}\n\nint main(int argc, char *argv[]) {\n    if (argc != 2) {\n        std::cerr \u003c\u003c \"Usage: \" \u003c\u003c argv[0] \u003c\u003c \" URL\" \u003c\u003c std::endl;\n        return 1;\n    }\n\n    coke::sync_wait(http_get(std::string(argv[1])));\n    return 0;\n}\n```\n\n- 更多示例请到[example](./example/)查看\n\n\n## 构建\n需要完整支持C++ 20 coroutine功能的编译器\n\n- GCC \u003e= 11\n- Clang \u003e= 15\n\n### Ubuntu 24.04/22.04\n若不需构建示例，可将`-D COKE_ENABLE_EXAMPLE=1`选项去掉。\n\n```bash\napt install -y gcc g++ libgtest-dev libssl-dev git cmake\ngit clone https://github.com/kedixa/coke.git\ncd coke\ngit clone https://github.com/sogou/workflow.git\ncmake -S workflow -B build.workflow -D CMAKE_CXX_STANDARD=20\ncmake --build build.workflow -j 8\ncmake -S . -B build.coke -D Workflow_DIR=workflow -D CMAKE_CXX_STANDARD=20 -D COKE_ENABLE_EXAMPLE=1\ncmake --build build.coke -j 8\n```\n\n### Ubuntu 20.04\n```bash\n# 添加源以使用gcc 11\nadd-apt-repository ppa:ubuntu-toolchain-r/test\napt install -y gcc-11 g++-11 libgtest-dev libssl-dev git cmake\ngit clone https://github.com/kedixa/coke.git\ncd coke\ngit clone https://github.com/sogou/workflow.git\ncmake -S workflow -B build.workflow -D CMAKE_CXX_STANDARD=20 -D CMAKE_C_COMPILER=gcc-11 -D CMAKE_CXX_COMPILER=g++-11\ncmake --build build.workflow -j 8\ncmake -S . -B build.coke -D Workflow_DIR=workflow -D CMAKE_CXX_STANDARD=20 -D CMAKE_C_COMPILER=gcc-11 -D CMAKE_CXX_COMPILER=g++-11 -D COKE_ENABLE_EXAMPLE=1\ncmake --build build.coke -j 8\n```\n\n### CentOS Stream 9\n```bash\ndnf install -y gcc gcc-c++ openssl-devel git cmake\n# 除安装软件包外，后续命令与Ubuntu 24.04一致\n# ...\n```\n\n## 注意事项\n### 关于具名任务\n`Workflow`中有些任务创建时可以指定名称，例如具名`WFTimerTask`可以根据名称被取消、具名`WFCounterTask`可以根据名称唤醒、具名`WFGoTask`可以根据名称区分计算队列等。`Coke`保留所有以`coke:`开始的名称，以满足自身使用。\n\n\n## LICENSE\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkedixa%2Fcoke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkedixa%2Fcoke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkedixa%2Fcoke/lists"}