Co
a tiny, portable, stackless coroutine in C++11
Install / Use
/learn @crazybie/CoREADME
Tiny Stackless Coroutine in C++14
based on Duff's device(https://en.wikipedia.org/wiki/Duff%27s_device)
Hightlights
- super lightweight with only one header file.
- support async & await with simple syntax.
- support await all in parallel.
- can very easily convert callback style API to awaitables.
- auto propagate exceptions to caller.
- can customize the scheduler.
- only need c++14.
- no other dependencies except STL.
Limitations
- the default scheduler is single threaded.
- memory & performance optimization.
Compiler support
- gcc > 4.9
- clang > 3.4
- vs 2017 (should work in 2015)
Simple example:
CoFunc(string) fs_read_all(const char* fname)
{
string content;
const char* cur;
int fd;
CoBegin;
CoAwait(fd, fs_open(fname, O_RDONLY));
for (;;) {
CoAwait(cur, fs_read(fd, content.length()));
if (cur == nullptr)
break;
content += cur;
}
CoAwait(fs_close(fd));
CoReturn(content);
CoEnd;
};
See example.cpp for more samples.
License
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
