Skip to content

pycub/caio

 
 

Repository files navigation

caio (C AsyncIO)

C non-blocking IO without callbacks.

Yes, Duff's device allows simulating coroutine in C.

Here is a minimal caio coroutine:

struct bar {
  int baz;
};


ASYNC
foo(struct caio_task *self, struct bar* state) {
  CAIO_BEGIN(self);

  /* Do something with state */
  state->baz++;

  CAIO_FINALLY(self);
}


int
main() {
  struct bar state = {0};
  return CAIO_FOREVER(foo, &state, 1);
}

Which translates to:

void
foo(struct caio_task *self, struct bar* state) {
  switch (self->current->line) {
    case 0:

      /* Do something with state */
      state->baz++;

    case -1:
  }
  self->status = CAIO_TERMINATED
}

About

C AsyncIO framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 93.9%
  • CMake 6.1%