Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4b8a5d9

Browse files
Add more details in examples (#74)
1 parent 21409df commit 4b8a5d9

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

‎README.md‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ VERSION=X.Y.Z \
8282
#include <msd/channel.hpp>
8383

8484
int main() {
85-
msd::channel<int> chan; // unbuffered
85+
msd::channel<int> chan; // Unbuffered
8686

8787
int in = 1;
8888
int out = 0;
@@ -98,23 +98,25 @@ int main() {
9898
```
9999

100100
```c++
101+
#include <cassert>
102+
101103
#include <msd/channel.hpp>
102104

103105
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
105107

106108
// 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)
110112
}
111113
```
112114

113115
```c++
114116
#include <msd/channel.hpp>
115117

116118
int main() {
117-
msd::channel<int> chan{2}; // buffered
119+
msd::channel<int> chan{2}; // Buffered
118120

119121
int in = 1;
120122
int out = 0;
@@ -124,9 +126,9 @@ int main() {
124126
chan << in;
125127

126128
// Read from channel
129+
chan.read(out);
127130
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)
130132
}
131133
```
132134

@@ -136,14 +138,14 @@ int main() {
136138
#include <msd/channel.hpp>
137139

138140
int main() {
139-
msd::channel<int> chan;
141+
msd::channel<int, msd::vector_storage<int>> chan;
140142

141143
int in1 = 1;
142144
int in2 = 2;
143145

144146
chan << in1 << in2;
145147

146-
for (const auto out : chan) { // blocks: waits forever for channel items
148+
for (const auto out : chan) { // Blocks: waits forever for channel items
147149
std::cout << out << '\n';
148150
}
149151
}
@@ -153,7 +155,8 @@ int main() {
153155
#include <msd/static_channel.hpp>
154156

155157
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>>
157160

158161
int in = 1;
159162
int out = 0;
@@ -165,7 +168,7 @@ int main() {
165168
// Read from channel
166169
chan.read(out);
167170
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)
169172
}
170173
```
171174

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /