Show HN: Team – Coroutines and async semantics for C++
team.s4y.us
team.s4y.us
#define async __r << [&]()
By writing 'async { ... }', we can turn any scope into a lambda function.Obviously this will require some care (in particular make sure the function is evaluated before we leave any scope with any used local variables).
acall [&,copyMe] { … }
In most cases, though, async will be used inside an await block; everything surrounding the await stays in scope. void fred()
{
int first = 'x';
int second = 'y';
wait_key([=](int c) {
if (c == x) {
wait_key([=](int d) {
if (d == y) {
printf("got x and y\n");
}
});
}
});
}
wait_key(void (*func)(int c)) registers a callback then returns. When a key is processed func is called.I use Ghostery which blocks the 'Github Ribbon' by default - it took me a while to find the repo ( https://github.com/Sidnicious/team ) since it wasn't linked prominently elsewhere on the page.
Thanks for sharing.