{"action":"created","issue":{"url":"https://api.github.com/repos/Reactive-Extensions/RxCpp/issues/154","labels_url":"https://api.github.com/repos/Reactive-Extensions/RxCpp/issues/154/labels{/name}","comments_url":"https://api.github.com/repos/Reactive-Extensions/RxCpp/issues/154/comments","events_url":"https://api.github.com/repos/Reactive-Extensions/RxCpp/issues/154/events","html_url":"https://github.com/Reactive-Extensions/RxCpp/pull/154","id":90539691,"number":154,"title":"add run loop scheduler","user":{"login":"kirkshoop","id":982716,"avatar_url":"https://avatars.githubusercontent.com/u/982716?v=3","gravatar_id":"","url":"https://api.github.com/users/kirkshoop","html_url":"https://github.com/kirkshoop","followers_url":"https://api.github.com/users/kirkshoop/followers","following_url":"https://api.github.com/users/kirkshoop/following{/other_user}","gists_url":"https://api.github.com/users/kirkshoop/gists{/gist_id}","starred_url":"https://api.github.com/users/kirkshoop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kirkshoop/subscriptions","organizations_url":"https://api.github.com/users/kirkshoop/orgs","repos_url":"https://api.github.com/users/kirkshoop/repos","events_url":"https://api.github.com/users/kirkshoop/events{/privacy}","received_events_url":"https://api.github.com/users/kirkshoop/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Reactive-Extensions/RxCpp/labels/cla-not-required","name":"cla-not-required","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-24T01:58:26Z","updated_at":"2015-06-24T03:07:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Reactive-Extensions/RxCpp/pulls/154","html_url":"https://github.com/Reactive-Extensions/RxCpp/pull/154","diff_url":"https://github.com/Reactive-Extensions/RxCpp/pull/154.diff","patch_url":"https://github.com/Reactive-Extensions/RxCpp/pull/154.patch"},"body":"I added the run loop scheduler to answer #151 \r\n\r\n## Usage\r\n\r\n```cpp\r\n#include \"rxcpp/rx.hpp\"\r\n// create alias' to simplify code\r\n// these are owned by the user so that\r\n// conflicts can be managed by the user.\r\nnamespace rx=rxcpp;\r\n\r\nint main()\r\n{\r\n    std::cout << std::setw(16) << std::this_thread::get_id() << \" <- main thread id\" << std::endl;\r\n\r\n    using namespace std::chrono;\r\n\r\n    rx::schedulers::run_loop rl;\r\n\r\n    auto mainthread = rx::observe_on_run_loop(rl);\r\n    auto workthread = rx::synchronize_new_thread();\r\n\r\n    rx::composite_subscription lifetime;\r\n\r\n    rx::observable<>::interval(workthread.now() + milliseconds(100), milliseconds(400)).\r\n        map([](int i){\r\n            std::cout << std::setw(16) << std::this_thread::get_id() << \": \" << i << std::endl;\r\n            return i;\r\n        }).\r\n        take_until(rx::observable<>::timer(seconds(1))).\r\n        subscribe_on(workthread).\r\n        observe_on(mainthread).\r\n        subscribe(lifetime, [&](int i){\r\n            std::cout << std::setw(16) << std::this_thread::get_id() << \": \" << i << std::endl;\r\n        });\r\n\r\n    while (lifetime.is_subscribed() || !rl.empty()) {\r\n        while (!rl.empty() && rl.peek().when < rl.now()) {\r\n            rl.dispatch();\r\n        }\r\n    }\r\n    return 0;\r\n}\r\n```\r\n\r\n## Output:\r\n\r\n```sh\r\n  0x7fff7b1cb300 <- main thread id\r\n     0x102047000: 1\r\n  0x7fff7b1cb300: 1\r\n     0x102047000: 2\r\n  0x7fff7b1cb300: 2\r\n     0x102047000: 3\r\n  0x7fff7b1cb300: 3\r\n```"},"comment":{"url":"https://api.github.com/repos/Reactive-Extensions/RxCpp/issues/comments/114710272","html_url":"https://github.com/Reactive-Extensions/RxCpp/pull/154#issuecomment-114710272","issue_url":"https://api.github.com/repos/Reactive-Extensions/RxCpp/issues/154","id":114710272,"user":{"login":"kirkshoop","id":982716,"avatar_url":"https://avatars.githubusercontent.com/u/982716?v=3","gravatar_id":"","url":"https://api.github.com/users/kirkshoop","html_url":"https://github.com/kirkshoop","followers_url":"https://api.github.com/users/kirkshoop/followers","following_url":"https://api.github.com/users/kirkshoop/following{/other_user}","gists_url":"https://api.github.com/users/kirkshoop/gists{/gist_id}","starred_url":"https://api.github.com/users/kirkshoop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kirkshoop/subscriptions","organizations_url":"https://api.github.com/users/kirkshoop/orgs","repos_url":"https://api.github.com/users/kirkshoop/repos","events_url":"https://api.github.com/users/kirkshoop/events{/privacy}","received_events_url":"https://api.github.com/users/kirkshoop/received_events","type":"User","site_admin":false},"created_at":"2015-06-24T03:07:07Z","updated_at":"2015-06-24T03:07:07Z","body":"Added fix for #153 "}}