summaryrefslogtreecommitdiff
path: root/Rx/v2/examples/doxygen/scope.cpp
blob: ae6521b731cbddf5a4c13b3f7f39573b48fe66dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "rxcpp/rx.hpp"

#include "rxcpp/rx-test.hpp"
#include "catch.hpp"

SCENARIO("scope sample"){
    printf("//! [scope sample]\n");
    typedef rxcpp::resource<std::vector<int>> resource;
    auto resource_factory = [](){return resource(rxcpp::util::to_vector({1, 2, 3, 4, 5}));};
    auto observable_factory = [](resource res){return rxcpp::observable<>::iterate(res.get());};
    auto values = rxcpp::observable<>::scope(resource_factory, observable_factory);
    values.
        subscribe(
            [](int v){printf("OnNext: %d\n", v);},
            [](){printf("OnCompleted\n");});
    printf("//! [scope sample]\n");
}