SkillAgentSearch skills...

Co

a tiny, portable, stackless coroutine in C++11

Install / Use

/learn @crazybie/Co
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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

The MIT License

Related Skills

View on GitHub
GitHub Stars11
CategoryDevelopment
Updated6mo ago
Forks1

Languages

C++

Security Score

87/100

Audited on Sep 27, 2025

No findings