Event loop (libuv)-driven coroutines for C++ that are easy to use with minimal syntax. Here's an example:
#include <team/team.h>
#include <iostream>
using namespace std;
using team::sleep;
template <typename T>
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.
You should check out these examples first:
hello_world
— How to run stuff asynchronously.timers
— Pretty similar. Includes a fire-and-forget example.channels
— Hacked-together Clojure/Go-style channels. Just proof that you can build other async constructs on top of team core. You can skip this.generators
— Python-style generators withyield
. Also hacked together, you can skip this.echo_server
— Start it up and use one or more copies ofnc
to throw packets its way.