conduit icon indicating copy to clipboard operation
conduit copied to clipboard

Implement Bidirectional Coroutines

Open nikhedonia opened this issue 7 years ago • 0 comments

Example:

auto pingPong = [](int x) -> reactor<int, int> {
   while(1) {
     x =  co_yield x;
   }
};

int main() {
  auto actor = pingPong(1);
  auto value = 0;
  while( actor.next(value) ) {
    value = actor.value() + 1;
   }
}

This can be later used to implement:

  • Haskell like io-monads
  • elm like effect systems
  • event-loops
  • parser combinators

PoC: https://godbolt.org/z/AW3UWC

nikhedonia avatar Oct 29 '18 13:10 nikhedonia