Skip to content

s4y/team

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Team

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.

Examples

You should check out these examples first:

  1. hello_world — How to run stuff asynchronously.
  2. timers — Pretty similar. Includes a fire-and-forget example.
  3. 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.
  4. generators — Python-style generators with yield. Also hacked together, you can skip this.
  5. echo_server — Start it up and use one or more copies of nc to throw packets its way.

Inspiration

Notes to self

About

Easy asynchrony for C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published