Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nbdd0121/CppCoroutine
Lightweight coroutine library for C++
https://github.com/nbdd0121/CppCoroutine
Last synced: 16 days ago
JSON representation
Lightweight coroutine library for C++
- Host: GitHub
- URL: https://github.com/nbdd0121/CppCoroutine
- Owner: nbdd0121
- Created: 2015-04-29T05:14:31.000Z (over 9 years ago)
- Default Branch: dev
- Last Pushed: 2015-04-30T14:25:04.000Z (over 9 years ago)
- Last Synced: 2024-07-31T22:58:32.723Z (3 months ago)
- Language: C
- Size: 160 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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 Function | Signature | Description
|-----------------|---------------------------------------------|-------------
| (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
| empty | bool() | Test whether a coroutine is retained by the current Coroutine instance
| stop | void\*(void\* = nullptr) | Force the coroutine to stop. not really recommended to use.
| resume | void\*(void\* = nullptr) | Resume/Start the coroutine
| status | Coroutine::Status() | Get the status of coroutine| Static Function | Signature | Description
|-----------------|---------------------------------------------|-------------
| yield | void\*(void\* = nullptr) | Yield the current coroutine
| current | Coroutine() | Get the running coroutine| Enumeration | Description
|-----------------|-------------
| READY | Coroutine is not yet started
| RUNNING | Coroutine is running
| SUSPENDED | yield() is called by coroutine and resume is not called after that
| STOPPED | stop() is called or the coroutine returns