Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/curve/channel
๐งต A C++ implementation of Rust's std::sync::mpsc::channel
https://github.com/curve/channel
cpp cpp17 cpp17-library cpp20 cpp20-library mpsc mpsc-channel threading
Last synced: 3 months ago
JSON representation
๐งต A C++ implementation of Rust's std::sync::mpsc::channel
- Host: GitHub
- URL: https://github.com/curve/channel
- Owner: Curve
- License: mit
- Created: 2022-07-30T14:04:15.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-08T19:47:31.000Z (10 months ago)
- Last Synced: 2024-03-08T20:54:18.710Z (10 months ago)
- Topics: cpp, cpp17, cpp17-library, cpp20, cpp20-library, mpsc, mpsc-channel, threading
- Language: C++
- Homepage:
- Size: 63.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐งต channel
A C++20 library that provides a rust like `std::sync::mpsc::channel` for inter-thread communication.
# ๐ฆ Installation
> [!NOTE]
> This library requires a C++20 capable compiler.
> In case you need support for C++17 checkout commits prior to [6977815](https://github.com/Curve/channel/tree/6977815409b4c3c02d74a7aee3fc29f01d632feb)- FetchContent
```cmake
include(FetchContent)
FetchContent_Declare(channel GIT_REPOSITORY "https://github.com/Curve/channel")FetchContent_MakeAvailable(channel)
target_link_libraries( cr::channel)
```
- Git Submodule
```bash
git submodule add "https://github.com/Curve/channel"
```
```cmake
# Somewhere in your CMakeLists.txt
add_subdirectory("")
target_link_libraries( cr::channel)
```# ๐ Examples
```cpp
#include
#include#include
auto [sender, receiver] = cr::channel();
// Spawn off expensive computations
std::thread t1([sender = std::move(sender)]() mutable
{
sender.send(expensive_computation_that_returns_int());
sender.send(another_expensive_computation_that_returns_float());
});// Do some useful work for awhile
// Let's see what that first answer was
std::cout << receiver.recv_as() << std::endl;// Let's see what that second answer was
std::cout << receiver.recv_as() << std::endl;
```> **Note**
> This library also supports methods like `try_recv` and `recv_timeout`.> For more examples see [tests](tests/)