-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.cpp
44 lines (33 loc) · 921 Bytes
/
example.cpp
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
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <sstream>
#include "CoroutineStream.h"
//////////////////////////////
// Test rig for implementation
//////////////////////////////
struct ExampleStreamProducer : public StreamProducer
{
virtual void produce(CoroutineStream &str)
{
for(size_t i=0; i<2; i++) {
std::stringstream ss;
ss << "ExampleData " << i;
str.write(ss.str());
std::cout << "Producer wrote '"
<< ss.str() << "' (" << ss.str().size() << ")"
<< std::endl;
}
}
};
int main()
{
ExampleStreamProducer p;
CoroutineStream s(p);
size_t cnt = 0;
while (const StreamChunk *c = s.peekChunk()) {
std::cout << "main stream read "
<< c->size()
<< " bytes of data: " << c->str() << std::endl;
s.consumeChunk();
}
return 0;
}