GithubHelp home page GithubHelp logo

plumpmath / cppcoroutine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nbdd0121/cppcoroutine

0.0 0.0 0.0 164 KB

Lightweight coroutine library for C++

C++ 73.67% C 16.98% Shell 2.01% Assembly 7.35%

cppcoroutine's Introduction

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

cppcoroutine's People

Contributors

nbdd0121 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.