Async in cweb

Module <cweb/async.h> — callback on the event loop

Defers execution of a callback until the next libevent loop iteration — useful for safely returning “onto the loop” from interrupt-like contexts or nested calls.

Type cweb_async_cb

typedef void (*cweb_async_cb)(void *user_data);

Function

int cweb_async(cweb_async_cb cb, void *user_data)

  • Purpose: Schedules cb(user_data) on the same event_base as the server.
  • Parameters:
    • cb — function with no return value.
    • user_data — optional NULL.
  • Return: 0 on success, otherwise error code (implementation).

Notes

  • Not a full job queue — only simple “defer to loop”.
  • Requires initialized global event base (cweb_run_server / g_event_base).