June 2018
Intermediate to advanced
348 pages
8h 45m
English
The RxCpp library does not have a notion of built-in main thread Scheduler. The closest you can do is to leverage the run_loop class to simulate scheduling in the main thread. In the following program, the Observable executes in a background thread, and the subscription methods run in the main thread. We are using subscribe_on and observe_on to achieve this objective:
//------------- RunLoop.cpp #include "rxcpp/rx.hpp" int main(){ //------------ Print the Main Thread Id printf("Main Thread Id is %dn", std::this_thread::get_id()); //------- Instantiate a run_loop object //------- which will loop in the main thread rxcpp::schedulers::run_loop rlp; //------ Create a Coordination functionfor run loop auto main_thread = ...