/coroutine

C++ Coroutine in Action

Primary LanguageC++Creative Commons Attribution 4.0 InternationalCC-BY-4.0

coroutine

C++ Coroutine in Action. Wiki

Codacy Badge Build Status Build status Build Status

The main goal of this library is ...

  • 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 !

Note

Interfaces

To support multiple compilers, this library replaces <experimental/coroutine>. This might lead to conflict with existing library like libcxx and VC++.
Prefer what you like. If the issue is severe, please create an issue.

// You can replace this header to <experimental/coroutine>
#include <coroutine/frame.h>

Generator and async generator

#include <coroutine/enumerable.hpp> // enumerable<T> : generator
#include <coroutine/sequence.hpp>   // sequence<T>   : async generator

Utility types are in the following headers

#include <coroutine/return.h>   // return type for coroutine
#include <coroutine/suspend.h>  // helper type for suspend / await
#include <coroutine/sync.h>     // synchronization utilities

Go language style channel to deliver data between coroutines

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

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

#include <coroutine/net.h>      // shows asnyc i/o

Build

Please reference .travis.yml and appveyor.yml to see build steps.

Tool Support

  • Visual Studio 2017 or later
    • msvc (vc141)
  • CMake
    • msvc
    • clang-cl: Windows with VC++ headers. Requires static linking
    • clang: Linux
    • AppleClang: Mac

This library only supports x64

Expect Clang 6 or later versions. Notice that the feature, c++ coroutine, was available since Clang 5

Test

Exploring test(example) codes will be helpful.

  • 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) win32.vcxproj in modules.

CMake Project

Expect there is a higher CMake project which uses this library.

cmake_minimum_required(VERSION 3.8)

# ...
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.