Skip to content

C++ 20 Coroutine in Action (Helpers + Test Code Examples)

License

Notifications You must be signed in to change notification settings

denchat/coroutine

 
 

Repository files navigation

coroutine

C++ Coroutine in Action.

Codacy Badge Build Status Build status Build Status

Purpose of this library

  • Help understanding of the C++ coroutine
  • 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 !

Signpost

  • Start with the wiki. You will visit the test/ and interface/ folder while reading the docs.
  • This repository has some custom implementation for the C++ Coroutine spec in the <coroutine/frame.h>

Developer Note

Architecture

This library is for x64.

Tool Support

For clang users, I do recommend Clang 6.0 or later versions.

To support multiple compilers, this library defines its own header, <coroutine/frame.h>. 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.

// This header includes/overrides <experimental/coroutine>
#include <coroutine/frame.h>

Generator and async generator

#include <coroutine/yield.hpp>  // enumerable<T> & sequence<T>

Utility types are in the following headers

#include <coroutine/return.h> // return type examples for convenience
#include <coroutine/concrt.h> // concurrency utilities over system API

Go language style channel to deliver data between coroutines. Supports awaitable read/write and select operation are possible. But it is slightly differnt from that of Go language.

#include <coroutine/channel.hpp>  // channel<T, Lockable>

Network Asnyc I/O and some helper functions are placed in one header.

#include <coroutine/net.h>      // async i/o for sockets

How To

Build

Please reference the build configurations.
Create an issue if you think another configuration is required.

  • Azure Pipelines
    • Visual Studio 2017 (Visual Studio Solution File)
    • Visual Studio 2017 (CMake)
    • Ubuntu 16.04 + Clang 6.0
    • Mac OS + AppleClang
    • Windows + Clang-cl
  • .travis.yml
    • Mac OS + AppleClang
    • Ubuntu 16.04 + Clang 7
    • iPhone OS : leetal/ios-cmake
    • Android NDK (SDK 24 - 27) + Clang 8
  • appveyor.yml
  • Works on my machine :D
    • Visual Studio 2019
    • Windows Subsystem for Linux (Ubuntu 18.04 + Clang 7.1.0)
    • Clang-cl (LLVM 7.0.1, 8.0) + Ninja

Test

Exploring test(example) codes will be helpful. The library uses 2 tools for its test.

  • Visual Studio Native Testing Tool
  • CMake generated project with Catch2

Import

Visual Studio Project

For Visual Studio users,
I recommend you to import(add reference) windows.vcxproj in modules.

CMake Project

Expect there is a higher CMake project which uses this library. For Android NDK, the minimum version of CMake is 3.14.

cmake_minimum_required(VERSION 3.8) # Android NDK requires 3.14

# ...
add_subdirectory(coroutine)

# ...
target_link_libraries(your_project
PUBLIC
    coroutine
)

Package Manager

Following package managers and build options are available.

  • vcpkg
    • x64-windows
    • x64-linux
    • x64-osx

License

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

About

C++ 20 Coroutine in Action (Helpers + Test Code Examples)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 90.3%
  • CMake 5.6%
  • Shell 3.1%
  • Other 1.0%