

Show HN: Team – Coroutines and async semantics for C++ - Sidnicious
http://team.s4y.us

======
CJefferson
I had a quick look in the source to see how this works (there is obviously
some macro fun going on). The macro cleverness (which I hadn't seen before)
was:

    
    
        #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).

~~~
jhallenworld
This has me thinking about doing Node.JS-style event processing with the new
C++ lambda syntax. I guess you can do it, but you must always copy [=] into
the closure so that the io function can return:

    
    
      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.

~~~
mkup
This approach to porting node.js library to C++11 is implemented in
node.native library:
[https://github.com/d5/node.native](https://github.com/d5/node.native)

------
j_s
Nice!

I use Ghostery which blocks the 'Github Ribbon' by default - it took me a
while to find the repo (
[https://github.com/Sidnicious/team](https://github.com/Sidnicious/team) )
since it wasn't linked prominently elsewhere on the page.

Thanks for sharing.

