Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s4y/team
Easy asynchrony for C++
https://github.com/s4y/team
Last synced: 17 days ago
JSON representation
Easy asynchrony for C++
- Host: GitHub
- URL: https://github.com/s4y/team
- Owner: s4y
- Created: 2013-04-11T15:22:50.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-02T18:54:34.000Z (over 9 years ago)
- Last Synced: 2024-04-14T09:09:56.879Z (7 months ago)
- Language: C++
- Homepage: http://team.s4y.us/
- Size: 468 KB
- Stars: 93
- Watchers: 11
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Team
Event loop ([libuv](https://github.com/joyent/libuv))-driven coroutines for C++ that are easy to use with minimal syntax. Here's an example:
```c++
#include
#includeusing namespace std;
using team::sleep;template
void log (T s) { cout << s << endl; }int main() {
await {
async { sleep(2); log("Slow thing done"); };
log("Started a slow thing");
async { sleep(1); log("Quick thing done"); };
log("Started a quick thing");
}log("Everything's done!");
}
```It prints this:
```
Started a slow thing
Started a quick thing
Quick thing done
Slow thing done
Everything's done!
```Calls block. `async { };` runs its body in a coroutine and returns control to the caller if it blocks, or when it finishes.
`await` blocks until every asynchronous task spawned inside it finishes.
Status: Relatively new. Gradually becoming useful though.
I want it to work like Tame but without code transformation (except for the C++ preprocessor), and thus able to be used with libraries written in a blocking style.
## Examples
You should check out these examples first:
1. [`hello_world`](https://github.com/Sidnicious/team/blob/master/examples/hello_world.cpp) — How to run stuff asynchronously.
2. [`timers`](https://github.com/Sidnicious/team/blob/master/examples/timers.cpp) — Pretty similar. Includes a fire-and-forget example.
3. [`channels`](https://github.com/Sidnicious/team/blob/master/examples/channels.cpp) — Hacked-together [Clojure/Go-style channels](http://blog.drewolson.org/blog/2013/07/04/clojure-core-dot-async-and-go-a-code-comparison/). Just proof that you can build other async constructs on top of team core. You can skip this.
4. [`generators`](https://github.com/Sidnicious/team/blob/master/examples/generators.cpp) — Python-style generators with `yield`. Also hacked together, you can skip this.
5. [`echo_server`](https://github.com/Sidnicious/team/blob/master/examples/echo_server.cpp) — Start it up and use one or more copies of `nc` to throw packets its way.## Inspiration
- [Tame](https://github.com/okws/sfslite/wiki/tame)
- [gevent](http://www.gevent.org/)## Notes to self
- http://www.rethinkdb.com/blog/improving-a-large-c-project-with-coroutines/
- http://www.rethinkdb.com/blog/making-coroutines-fast/