# coroutine **Repository Path**: shun_dev/coroutine ## Basic Information - **Project Name**: coroutine - **Description**: C++ 20 Coroutines in Action (Helpers + Test Code Examples) - **Primary Language**: C++ - **License**: CC-BY-4.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-01-10 - **Last Updated**: 2022-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # coroutine C++ 20 Coroutines in Action [![Build Status](https://dev.azure.com/luncliff/personal/_apis/build/status/luncliff.coroutine?branchName=master)](https://dev.azure.com/luncliff/personal/_build/latest?definitionId=27&branchName=master) [![Build status](https://ci.appveyor.com/api/projects/status/vpjssf4g6cv4a4ys/branch/master?svg=true)](https://ci.appveyor.com/project/luncliff/coroutine/branch/master) [![Build Status](https://travis-ci.org/luncliff/coroutine.svg?branch=master)](https://travis-ci.org/luncliff/coroutine) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/38aa16f6d7e046898af3835918c0cd5e)](https://app.codacy.com/app/luncliff/coroutine?utm_source=github.com&utm_medium=referral&utm_content=luncliff/coroutine&utm_campaign=Badge_Grade_Dashboard) [![](https://sonarcloud.io/api/project_badges/measure?project=luncliff_coroutine&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=luncliff_coroutine) [![](https://sonarcloud.io/api/project_badges/measure?project=luncliff_coroutine&metric=ncloc)](https://sonarcloud.io/dashboard?id=luncliff_coroutine) ### Purpose of this repository * Help understanding of the C++ Coroutines * Provide meaningful design example with the feature In that perspective, the library will be maintained as small as possible. Have fun with them. And try your own coroutines! **If you are looking for another materials, visit [the MattPD's collection](https://gist.github.com/MattPD/9b55db49537a90545a90447392ad3aeb#file-cpp-std-coroutines-draft-md)!** * Start with the [GitHub Pages](https://luncliff.github.io/coroutine) :) You will visit the [test/](./test/) and [interface/](./interface/coroutine) folder while reading the docs. * This repository has some custom(and partial) implementation for the C++ Coroutines in the [``](./interface/coroutine/frame.h). It can be activated with macro `USE_PORTABLE_COROUTINE_HANDLE` ### Pre-requisite * [Microsoft GSL v3.0+](https://github.com/microsoft/GSL/releases) The installation of this library will install it together. All other required modules for build/test will be placed in [external/](./external). ### Tool Support * [CMake](./CMakeLists.txt) * `msvc` * `clang-cl`: Works with VC++ headers * `clang`: Linux * `AppleClang`: Mac #### Known Issues > TBA ## How To ### Setup Simply clone and initialize submodules recursively :) ```bash git clone https://github.com/luncliff/coroutine pushd coroutine git submodule update --init --recursive popd ``` ### Test Exploring [test(example) codes](./test) will be helpful. The library uses CTest for its test. AppVeyor & Travis CI build log will show the execution of them. ### Import If you want some tool support, please let me know. I'm willing to learn about it. #### CMake 3.12+ Expect there is a higher CMake project which uses this library. The library exports 3 targets. * coroutine_portable * `` * `` * `` * coroutine_system * requires: coroutine_portable * `` * `` * `` * `` * coroutine_net * requires: coroutine_system * `` ```cmake cmake_minimum_required(VERSION 3.12) find_package(coroutine CONFIG REQUIRED) # or add_subdirectory(coroutine) if you want to be simple target_link_libraries(main PUBLIC coroutine_portable coroutine_system coroutine_net ) ``` ## Developer Note ### [Interface](./interface) #### Portable To support multiple compilers, this library defines its own header, ``. This might lead to conflict with existing library (libc++ and VC++). If there is a collision(build issue), please make an issue in this repo so I can fix it. ```c++ // This header includes/overrides #include ``` Utility types are in the following headers. With the macro `USE_EXPERIMENTAL_COROUTINE`, you can enforce `` instead of `` ```c++ // return/promise types for coroutine functions #define USE_EXPERIMENTAL_COROUTINE #include ``` Generator is named `coro::enumerable` here. For now you can see various description for the concept in C++ conference talks in Youtube. If you want better implementation or want to see another generators, visit the https://github.com/Quuxplusone/coro :D ```c++ // enumerable #include ``` Go language style channel to deliver data between coroutines. It Supports awaitable read/write and select operation are possible. If you don't know the language, never worry. There was a talk in CppCon * [CppCon 2016: John Bandela "Channels - An alternative to callbacks and futures"](https://www.youtube.com/watch?v=N3CkQu39j5I) But it is slightly different from that of the Go language because we don't have a built-in scheduler in C++. Furthermore Goroutine is quite different from the C++ Coroutines. It may not a necessary feature since there are so much of the channel implementation, but you may feel curiosity about it. ```c++ // channel with Lockable #define USE_EXPERIMENTAL_COROUTINE #include ``` #### System The library doesn't provides platform-neutral abstraction. ```c++ // #include // requires ms-gsl // #include // already used by the following headers #include #include #include #include ``` Please reference test codes for their usage. #### Network Async I/O with awaitable types for socket operation and `poll_net_tasks` to multiplex control flow. ```c++ #include ``` Please reference test codes for its usage. ## License Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.