-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchannel.cpp
More file actions
34 lines (27 loc) · 768 Bytes
/
Copy pathchannel.cpp
File metadata and controls
34 lines (27 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* A close approximation of [channels][] (and [select][]) is implemented along
* with most of the functional unit test suite. This example sends a message
* over an unbuffered channel from one thread to another.
*
* [channels]: https://tour.golang.org/concurrency/2
* [select]: https://tour.golang.org/concurrency/5
*/
#include <iostream>
#include <string>
#include <thread>
#include <bongo/bongo.h>
using namespace std::string_literals;
int main() try {
bongo::chan<std::string> c;
auto t = std::thread{[&]() {
c << "Golang Rules!"s;
}};
decltype(c)::recv_type v; // std::optional<std::string>
v << c;
std::cout << *v << "\n";
t.join();
return 0;
} catch (std::exception const& e) {
std::cerr << e.what() << "\n";
return 1;
}