Skip to content

coio

A C++ asynchronous I/O library built on the sender/receiver model (std::execution), with first-class coroutine support.

#include <coio/core.h>
#include <coio/execution_context.h>
#include <coio/utils/timer.h>

using namespace std::chrono_literals;

auto job(coio::time_loop::scheduler sched, int value, std::chrono::seconds delay) -> coio::task<int> {
    coio::timer timer{sched};
    co_await timer.async_wait(delay);
    co_return value;
}

auto main() -> int {
    coio::time_loop context;
    auto [i, j] = coio::this_thread::sync_wait(coio::when_all(
        job(context.get_scheduler(), 114, 2s),
        job(context.get_scheduler(), 514, 1s),
        [&context]() -> coio::task<> { context.run(); co_return; }()
    )).value();
    // i == 114, j == 514, total wall time ≈ 2s
}

Features

Note

Async I/O and networking backends are currently implemented on Linux (epoll and io_uring; the io_uring backend requires kernel 5.19 or newer) and Windows (IOCP).

Where to start

Goal Page
Build and install the library Getting Started
Understand senders, coroutines, and cancellation in coio Concepts
Write your first async program task, time_loop
Do network I/O Sockets, I/O Model & Lifetime
Understand the threading contracts Execution Contexts, Thread Safety Summary

License

coio is distributed under the MIT License.