Pheme is a C++20 asynchronous runtime designed for systems supporting the kqueue event notification interface. It provides a framework for managing non-blocking I/O and concurrent tasks through C++ coroutines.
The library operates on a hybrid model that separates I/O multiplexing from CPU-bound execution:
- Event Loop: The AsyncContext utilizes a kqueue file descriptor to monitor socket readiness and internal notifications via a wakeup pipe.
- Coroutine Integration: Standard socket operations—accept, read, and write—are wrapped in custom awaiters that suspend the calling coroutine until the kernel signals readiness.
- Task Offloading: For functions that would otherwise block the event loop, spawn_blocking moves the execution to a ThreadPool and resumes the coroutine once the result is available.
- Resource Management: The TcpSocket and AsyncTask classes use RAII to manage file descriptor lifetimes and coroutine state cleanup.
- Platform Support: Uses sys/event.h, limiting compatibility to BSD-derived systems like macOS.
- I/O Handling: Uses EV_ONESHOT for event registrations, requiring re-registration for subsequent I/O operations.
- Concurrency: Employs a Scheduler with a thread-safe task queue to distribute work among background threads.
- Error Propagation: Exceptions within asynchronous tasks are captured and re-thrown upon coroutine resumption.