Skip to content

Merge scheduler #604

@czajah

Description

@czajah

Hi, I have few questions

  1. Do I need to add scheduler to merge operator in this code? When do I have to provide it and why?

    auto src1 = rxcpp::sources::interval(std::chrono::seconds(1), rxcpp::observe_on_new_thread())
    .map([](auto i){
    return "1# i: " + std::to_string(i);
    });

    auto src2 = rxcpp::sources::interval(std::chrono::milliseconds(500), rxcpp::observe_on_new_thread())
    .map([](auto i){
    return "2# i: " + std::to_string(i);
    });

    src1
    .merge(src2)
    .subscribe([](auto s){
    std::cout << s << std::endl;
    });

  2. Can I do something like this if I want to have only one thread instead of two (or three in case if I have to create anothed one for merge operator)?

    auto sc = rxcpp::schedulers::make_new_thread();
    auto w = sc.create_worker();
    auto so = rxcpp::identity_same_worker(w);

    auto src1 = rxcpp::sources::interval(std::chrono::seconds(1), so)
    .map([](auto i){
    return "1# i: " + std::to_string(i);
    });

    auto src2 = rxcpp::sources::interval(std::chrono::milliseconds(500), so)
    .map([](auto i){
    return "2# i: " + std::to_string(i);
    });

    src1
    .merge(src2)
    .subscribe([](auto s){
    std::cout << s << std::endl;
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions