@@ -82,7 +82,7 @@ VERSION=X.Y.Z \
82
82
#include < msd/channel.hpp>
83
83
84
84
int main () {
85
- msd::channel<int> chan; // unbuffered
85
+ msd::channel<int> chan; // Unbuffered
86
86
87
87
int in = 1;
88
88
int out = 0;
@@ -98,23 +98,25 @@ int main() {
98
98
```
99
99
100
100
``` c++
101
+ #include < cassert>
102
+
101
103
#include < msd/channel.hpp>
102
104
103
105
int main () {
104
- msd::channel<int, msd::vector_storage<int>> chan{2}; // buffered
106
+ msd::channel<int, msd::vector_storage<int>> chan{2}; // Buffered with vector storage
105
107
106
108
// Send to channel
107
- chan << 1;
108
- chan << 2;
109
- chan << 3; // blocks because capacity is 2 (and no one reads from channel)
109
+ chan << 1; // Throws if the channel is closed (after chan.close())
110
+ assert ( chan.write(2)); // Returns false if the channel is closed (after chan.close())
111
+ chan << 3; // Blocks because the capacity is 2 (and no one reads from channel)
110
112
}
111
113
```
112
114
113
115
``` c++
114
116
#include < msd/channel.hpp>
115
117
116
118
int main () {
117
- msd::channel<int> chan{2}; // buffered
119
+ msd::channel<int> chan{2}; // Buffered
118
120
119
121
int in = 1;
120
122
int out = 0;
@@ -124,9 +126,9 @@ int main() {
124
126
chan << in;
125
127
126
128
// Read from channel
129
+ chan.read(out);
127
130
chan >> out;
128
- chan >> out;
129
- chan >> out; // blocks because channel is empty (and no one writes on it)
131
+ chan >> out; // Blocks because the channel is empty (and no one writes on it)
130
132
}
131
133
```
132
134
@@ -136,14 +138,14 @@ int main() {
136
138
#include < msd/channel.hpp>
137
139
138
140
int main () {
139
- msd::channel<int> chan;
141
+ msd::channel<int, msd::vector_storage<int> > chan;
140
142
141
143
int in1 = 1;
142
144
int in2 = 2;
143
145
144
146
chan << in1 << in2;
145
147
146
- for (const auto out : chan) { // blocks : waits forever for channel items
148
+ for (const auto out : chan) { // Blocks : waits forever for channel items
147
149
std::cout << out << '\n';
148
150
}
149
151
}
@@ -153,7 +155,8 @@ int main() {
153
155
#include < msd/static_channel.hpp>
154
156
155
157
int main () {
156
- msd::static_channel<int, 2> chan{}; // always buffered
158
+ msd::static_channel<int, 2> chan{}; // Always buffered
159
+ // Same as msd::channel<int, msd::array_storage<int, 2>>
157
160
158
161
int in = 1;
159
162
int out = 0;
@@ -165,7 +168,7 @@ int main() {
165
168
// Read from channel
166
169
chan.read(out);
167
170
chan.read(out);
168
- chan.read(out); // blocks because channel is empty (and no one writes on it)
171
+ chan.read(out); // Blocks because the channel is empty (and no one writes on it)
169
172
}
170
173
```
171
174
0 commit comments