2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Improve rpl::combine() and rpl::start().

This commit is contained in:
John Preston
2017-09-18 19:39:45 +03:00
parent 5e7aa4ff81
commit ee9763c98f
26 changed files with 2119 additions and 403 deletions

View File

@@ -157,6 +157,21 @@ TEST_CASE("basic producer tests", "[rpl::producer]") {
saved.destroy();
REQUIRE(*lifetimeEndCount == 3);
}
SECTION("tuple producer test") {
auto result = std::make_shared<int>(0);
{
producer<std::tuple<int, double>>([=](auto &&consumer) {
consumer.put_next(std::make_tuple(1, 2.));
return lifetime();
}).start([=](int a, double b) {
*result = a + int(b);
}, [=](no_error error) {
}, [=]() {
});
}
REQUIRE(*result == 3);
}
}
TEST_CASE("basic event_streams tests", "[rpl::event_stream]") {
@@ -447,4 +462,35 @@ TEST_CASE("basic piping tests", "[rpl::producer]") {
}
REQUIRE(*sum == 3);
}
SECTION("rich start calls") {
auto sum = std::make_shared<int>(0);
{
auto alive = lifetime();
producer<int, int>([=](auto &&consumer) {
consumer.put_next(33);
return lifetime();
})
| start([=](int value) {
*sum += value;
}, alive);
producer<no_value, int>([=](auto &&consumer) {
consumer.put_error(33);
return lifetime();
})
| start([](no_value) {
}, [=](int value) {
*sum += value;
}, alive);
producer<int, int>([=](auto &&consumer) {
consumer.put_next(33);
consumer.put_done();
return lifetime();
})
| start([=] {
*sum += 33;
}, alive);
}
REQUIRE(*sum == 99);
}
}