https://github.com/maikel/glib-senders
Senders and Receivers for the GNOME Glib library
https://github.com/maikel/glib-senders
coroutines cpp gtk stdexec
Last synced: 2 months ago
JSON representation
Senders and Receivers for the GNOME Glib library
- Host: GitHub
- URL: https://github.com/maikel/glib-senders
- Owner: maikel
- License: unlicense
- Created: 2023-01-25T20:22:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-30T15:55:04.000Z (about 2 years ago)
- Last Synced: 2025-02-01T10:41:31.529Z (4 months ago)
- Topics: coroutines, cpp, gtk, stdexec
- Language: C++
- Homepage:
- Size: 96.7 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

Senders and Receivers for the GNOME Glib library
===============================================This is a small C++ library that glues together the Glib event loop and the current executor proposal for C++.
It can be used to compose asynchronous tasks in a Glib event loop.Since single-valued senders can be automatically converted to awaitable objects, the library also provides a way to use C++ coroutines in a Glib event loop.
The library requires C++20.
Example
```cpp
#include "glib-senders/glib_io_context.hpp"
#include "glib-senders/file_descriptor.hpp"#include
using namespace gsenders;
exec::task write(file_descriptor fd, std::span buffer) {
while (!buffer.empty()) {
buffer = co_await async_write_some(fd, buffer);
}
}exec::task echo(file_descriptor in, file_descriptor out) {
char buffer[1024];
int n = 0;
for (int n = 0; n < 10; ++n) {
std::span received = co_await async_read_some(in, buffer);
co_await write(out, received);
}
}int main() {
glib_io_context ctx{};
file_descriptor in{STDIN_FILENO};
file_descriptor out{STDOUT_FILENO};
stdexec::start_detached(echo(in, out) | stdexec::then([&] { ctx.stop(); }));
ctx.run();
}
```