Skip to content

Repository files navigation

C++Coroutine

This is a extremely lightweight coroutine library for C++ Consist of only 4 file (1 .c, 1 .cc and 2 .h files)

Supported platform and compiler are linux/windows compiled via gcc/clang/visual c++ targeted on x86 or x64 devices.

This is designed for single-threaded programs; using coroutine in multiple threads at the same time is not supported currently

A example of using this (implementation of async/await and promise) can be found at https://gist.github.com/nbdd0121/0c739ca139d58ae12290

API Reference

The main class is norlit::coroutine::Coroutine. The norlit::coroutine::context_t and series of functions are available if you want to use low-level ucontext-like functions.

Member FunctionSignatureDescription
(constructor)Coroutine()Initialize a empty instance that refers to no coroutine
(constructor)Coroutine(Coroutine&&)Move constructor; original Coroutine will refer to no coroutine
(constructor)Coroutine(const Coroutine&)Copy constructor; two Coroutine instances refer to the same coroutine
(constructor)Coroutine(std::function<void*(void*)>)Create a new oroutine with given function
(destructor)~Coroutine()Delete the coroutine if it is pointed by none of the Coroutine instance
operator =void(Coroutine&&)Reassign the current Coroutine instance
operator =void(const Coroutine&)Reassign the current Coroutine instance
emptybool()Test whether a coroutine is retained by the current Coroutine instance
stopvoid*(void* = nullptr)Force the coroutine to stop. not really recommended to use.
resumevoid*(void* = nullptr)Resume/Start the coroutine
statusCoroutine::Status()Get the status of coroutine
Static FunctionSignatureDescription
yieldvoid*(void* = nullptr)Yield the current coroutine
currentCoroutine()Get the running coroutine
EnumerationDescription
READYCoroutine is not yet started
RUNNINGCoroutine is running
SUSPENDEDyield() is called by coroutine and resume is not called after that
STOPPEDstop() is called or the coroutine returns

About

Lightweight coroutine library for C++

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages