Commit 97024e8c authored by Dominik Charousset's avatar Dominik Charousset

Add trailing commas for nicer formatting

parent 460a1953
......@@ -58,38 +58,46 @@ void push(std::deque<T>& xs, downstream<T>& out, size_t num) {
VARARGS_TESTEE(int_file_reader, size_t buf_size) {
using buf = std::deque<int32_t>;
return {[=](string& fname) -> result<stream<int32_t>> {
CAF_CHECK_EQUAL(fname, "numbers.txt");
return attach_stream_source(
self,
// initialize state
[=](buf& xs) {
xs.resize(buf_size);
std::iota(xs.begin(), xs.end(), 1);
},
// get next element
[](buf& xs, downstream<int32_t>& out, size_t num) { push(xs, out, num); },
// check whether we reached the end
[=](const buf& xs) { return xs.empty(); });
}};
return {
[=](string& fname) -> result<stream<int32_t>> {
CAF_CHECK_EQUAL(fname, "numbers.txt");
return attach_stream_source(
self,
// initialize state
[=](buf& xs) {
xs.resize(buf_size);
std::iota(xs.begin(), xs.end(), 1);
},
// get next element
[](buf& xs, downstream<int32_t>& out, size_t num) {
push(xs, out, num);
},
// check whether we reached the end
[=](const buf& xs) { return xs.empty(); });
},
};
}
VARARGS_TESTEE(string_file_reader, size_t buf_size) {
using buf = std::deque<string>;
return {[=](string& fname) -> result<stream<string>> {
CAF_CHECK_EQUAL(fname, "strings.txt");
return attach_stream_source(
self,
// initialize state
[=](buf& xs) {
for (size_t i = 0; i < buf_size; ++i)
xs.emplace_back("some string data");
},
// get next element
[](buf& xs, downstream<string>& out, size_t num) { push(xs, out, num); },
// check whether we reached the end
[=](const buf& xs) { return xs.empty(); });
}};
return {
[=](string& fname) -> result<stream<string>> {
CAF_CHECK_EQUAL(fname, "strings.txt");
return attach_stream_source(
self,
// initialize state
[=](buf& xs) {
for (size_t i = 0; i < buf_size; ++i)
xs.emplace_back("some string data");
},
// get next element
[](buf& xs, downstream<string>& out, size_t num) {
push(xs, out, num);
},
// check whether we reached the end
[=](const buf& xs) { return xs.empty(); });
},
};
}
TESTEE_STATE(sum_up) {
......@@ -98,24 +106,26 @@ TESTEE_STATE(sum_up) {
TESTEE(sum_up) {
using intptr = int*;
return {[=](stream<int32_t>& in) {
return attach_stream_sink(
self,
// input stream
in,
// initialize state
[=](intptr& x) { x = &self->state.x; },
// processing step
[](intptr& x, int32_t y) { *x += y; },
// cleanup and produce result message
[=](intptr&, const error&) {
CAF_MESSAGE(self->name() << " is done");
});
},
[=](join_atom, actor src) {
CAF_MESSAGE(self->name() << " joins a stream");
self->send(self * src, join_atom::value, ints_atom::value);
}};
return {
[=](stream<int32_t>& in) {
return attach_stream_sink(
self,
// input stream
in,
// initialize state
[=](intptr& x) { x = &self->state.x; },
// processing step
[](intptr& x, int32_t y) { *x += y; },
// cleanup and produce result message
[=](intptr&, const error&) {
CAF_MESSAGE(self->name() << " is done");
});
},
[=](join_atom, actor src) {
CAF_MESSAGE(self->name() << " joins a stream");
self->send(self * src, join_atom::value, ints_atom::value);
},
};
}
TESTEE_STATE(collect) {
......@@ -123,28 +133,30 @@ TESTEE_STATE(collect) {
};
TESTEE(collect) {
return {[=](stream<string>& in) {
return attach_stream_sink(
self,
// input stream
in,
// initialize state
[](unit_t&) {
// nop
},
// processing step
[=](unit_t&, string y) {
self->state.strings.emplace_back(std::move(y));
},
// cleanup and produce result message
[=](unit_t&, const error&) {
CAF_MESSAGE(self->name() << " is done");
});
},
[=](join_atom, actor src) {
CAF_MESSAGE(self->name() << " joins a stream");
self->send(self * src, join_atom::value, strings_atom::value);
}};
return {
[=](stream<string>& in) {
return attach_stream_sink(
self,
// input stream
in,
// initialize state
[](unit_t&) {
// nop
},
// processing step
[=](unit_t&, string y) {
self->state.strings.emplace_back(std::move(y));
},
// cleanup and produce result message
[=](unit_t&, const error&) {
CAF_MESSAGE(self->name() << " is done");
});
},
[=](join_atom, actor src) {
CAF_MESSAGE(self->name() << " joins a stream");
self->send(self * src, join_atom::value, strings_atom::value);
},
};
}
using int_downstream_manager = broadcast_downstream_manager<int>;
......@@ -210,28 +222,30 @@ TESTEE_STATE(stream_multiplexer) {
TESTEE(stream_multiplexer) {
self->state.stage = make_counted<fused_stage>(self);
return {[=](join_atom, ints_atom) {
auto& stg = self->state.stage;
CAF_MESSAGE("received 'join' request for integers");
auto result = stg->add_unchecked_outbound_path<int>();
stg->out().assign<int_downstream_manager>(result);
return result;
},
[=](join_atom, strings_atom) {
auto& stg = self->state.stage;
CAF_MESSAGE("received 'join' request for strings");
auto result = stg->add_unchecked_outbound_path<string>();
stg->out().assign<string_downstream_manager>(result);
return result;
},
[=](const stream<int32_t>& in) {
CAF_MESSAGE("received handshake for integers");
return self->state.stage->add_unchecked_inbound_path(in);
},
[=](const stream<string>& in) {
CAF_MESSAGE("received handshake for strings");
return self->state.stage->add_unchecked_inbound_path(in);
}};
return {
[=](join_atom, ints_atom) {
auto& stg = self->state.stage;
CAF_MESSAGE("received 'join' request for integers");
auto result = stg->add_unchecked_outbound_path<int>();
stg->out().assign<int_downstream_manager>(result);
return result;
},
[=](join_atom, strings_atom) {
auto& stg = self->state.stage;
CAF_MESSAGE("received 'join' request for strings");
auto result = stg->add_unchecked_outbound_path<string>();
stg->out().assign<string_downstream_manager>(result);
return result;
},
[=](const stream<int32_t>& in) {
CAF_MESSAGE("received handshake for integers");
return self->state.stage->add_unchecked_inbound_path(in);
},
[=](const stream<string>& in) {
CAF_MESSAGE("received handshake for strings");
return self->state.stage->add_unchecked_inbound_path(in);
},
};
}
struct config : actor_system_config {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment